From 41ed4d12c83ae047af74c19b5e6acb462b1d592b Mon Sep 17 00:00:00 2001 From: shahramn Date: Fri, 1 Mar 2024 12:10:27 +0000 Subject: [PATCH] Tools: Dead code removal --- tools/bufr_compare.cc | 25 ++++++------------------- tools/grib_compare.cc | 15 ++------------- tools/gts_compare.cc | 10 +++------- tools/metar_compare.cc | 18 +++--------------- 4 files changed, 14 insertions(+), 54 deletions(-) diff --git a/tools/bufr_compare.cc b/tools/bufr_compare.cc index c6714fedb..3fa715669 100644 --- a/tools/bufr_compare.cc +++ b/tools/bufr_compare.cc @@ -236,7 +236,7 @@ int grib_tool_before_getopt(grib_runtime_options* options) int grib_tool_init(grib_runtime_options* options) { - int ret = 0, i; + int ret = 0; grib_context* context = grib_context_get_default(); options->strict = 1; @@ -315,16 +315,6 @@ int grib_tool_init(grib_runtime_options* options) compare_double = &compare_double_absolute; if (grib_options_on("R:")) { global_tolerance = 0; - for (i = 0; i < options->tolerance_count; i++) { - if (!strcmp((options->tolerance[i]).name, "all")) { - global_tolerance = (options->tolerance[i]).double_value; - break; - } - if (!strcmp((options->tolerance[i]).name, "global")) { - global_tolerance = (options->tolerance[i]).double_value; - break; - } - } compare_double = &compare_double_relative; compareAbsolute = 0; } @@ -342,9 +332,9 @@ int grib_tool_init(grib_runtime_options* options) tolerance_factor = atof(grib_options_get_option("t:")); if (grib_options_on("R:")) { - char* sarg = grib_options_get_option("R:"); + char* sarg = grib_options_get_option("R:"); options->tolerance_count = MAX_KEYS; - ret = parse_keyval_string(tool_name, sarg, 1, GRIB_TYPE_DOUBLE, options->tolerance, &(options->tolerance_count)); + ret = parse_keyval_string(tool_name, sarg, 1, GRIB_TYPE_DOUBLE, options->tolerance, &(options->tolerance_count)); if (ret == GRIB_INVALID_ARGUMENT) { usage(); exit(1); @@ -771,11 +761,10 @@ static int compare_values(grib_runtime_options* options, grib_handle* handle1, g return GRIB_COUNT_MISMATCH; } */ - if (options->mode != MODE_BUFR) { + Assert(options->mode == MODE_BUFR); /* TODO: Ignore missing values for keys in BUFR. Not yet implemented */ //isMissing1 = ((grib_is_missing(handle1, name, &err1) == 1) && (err1 == 0)) ? 1 : 0; //isMissing2 = ((grib_is_missing(handle2, name, &err2) == 1) && (err2 == 0)) ? 1 : 0; - } if ((isMissing1 == 1) && (isMissing2 == 1)) { // if (verbose) printf(" is set to missing in both fields\n"); @@ -1081,16 +1070,14 @@ static int compare_values(grib_runtime_options* options, grib_handle* handle1, g break; case GRIB_TYPE_BYTES: - if (options->mode == MODE_BUFR) - return 0; + return 0; // Not in BUFR break; case GRIB_TYPE_LABEL: break; default: - if (verbose) - printf("\n"); + if (verbose) printf("\n"); printInfo(handle1); save_error(c, name); printf("Cannot compare [%s], unsupported type %d\n", name, type1); diff --git a/tools/grib_compare.cc b/tools/grib_compare.cc index e70119d6d..f9f4d0977 100644 --- a/tools/grib_compare.cc +++ b/tools/grib_compare.cc @@ -330,18 +330,7 @@ int grib_tool_init(grib_runtime_options* options) global_tolerance = 0; compare_double = &compare_double_absolute; if (grib_options_on("R:")) { - int i; global_tolerance = 0; - for (i = 0; i < options->tolerance_count; i++) { - if (!strcmp((options->tolerance[i]).name, "all")) { - global_tolerance = (options->tolerance[i]).double_value; - break; - } - if (!strcmp((options->tolerance[i]).name, "global")) { - global_tolerance = (options->tolerance[i]).double_value; - break; - } - } compare_double = &compare_double_relative; compareAbsolute = 0; } @@ -374,9 +363,9 @@ int grib_tool_init(grib_runtime_options* options) tolerance_factor = atof(grib_options_get_option("T:")); if (grib_options_on("R:")) { - char* sarg = grib_options_get_option("R:"); + char* sarg = grib_options_get_option("R:"); options->tolerance_count = MAX_KEYS; - ret = parse_keyval_string(tool_name, sarg, 1, GRIB_TYPE_DOUBLE, options->tolerance, &(options->tolerance_count)); + ret = parse_keyval_string(tool_name, sarg, 1, GRIB_TYPE_DOUBLE, options->tolerance, &(options->tolerance_count)); if (ret == GRIB_INVALID_ARGUMENT) { usage(); exit(1); diff --git a/tools/gts_compare.cc b/tools/gts_compare.cc index cedbfa4b6..9133b3435 100644 --- a/tools/gts_compare.cc +++ b/tools/gts_compare.cc @@ -439,12 +439,10 @@ static int compare_values(const grib_runtime_options* options, grib_handle* h1, save_error(c, name); return err; } - - //if (options->mode != MODE_GTS) { + Assert(options->mode == MODE_GTS); /* TODO: Ignore missing values for keys in GTS. Not yet implemented */ //isMissing1 = ((grib_is_missing(h1, name, &err1) == 1) && (err1 == 0)) ? 1 : 0; //isMissing2 = ((grib_is_missing(h2, name, &err2) == 1) && (err2 == 0)) ? 1 : 0; - //} if ((isMissing1 == 1) && (isMissing2 == 1)) { if (verbose) @@ -573,10 +571,8 @@ static int compare_values(const grib_runtime_options* options, grib_handle* h1, break; case GRIB_TYPE_BYTES: - if (options->mode == MODE_GTS) { - // We do not want to compare the message itself - return 0; - } + // We do not want to compare the message itself + return 0; break; case GRIB_TYPE_LABEL: diff --git a/tools/metar_compare.cc b/tools/metar_compare.cc index 973794988..e4318bd44 100644 --- a/tools/metar_compare.cc +++ b/tools/metar_compare.cc @@ -249,16 +249,6 @@ int grib_tool_init(grib_runtime_options* options) compare_double = &compare_double_absolute; if (grib_options_on("R:")) { global_tolerance = 0; - for (int i = 0; i < options->tolerance_count; i++) { - if (!strcmp((options->tolerance[i]).name, "all")) { - global_tolerance = (options->tolerance[i]).double_value; - break; - } - if (!strcmp((options->tolerance[i]).name, "global")) { - global_tolerance = (options->tolerance[i]).double_value; - break; - } - } compare_double = &compare_double_relative; compareAbsolute = 0; } @@ -276,7 +266,7 @@ int grib_tool_init(grib_runtime_options* options) tolerance_factor = atof(grib_options_get_option("t:")); if (grib_options_on("R:")) { - char* sarg = grib_options_get_option("R:"); + char* sarg = grib_options_get_option("R:"); options->tolerance_count = MAX_KEYS; int err = parse_keyval_string(tool_name, sarg, 1, GRIB_TYPE_DOUBLE, options->tolerance, &(options->tolerance_count)); if (err == GRIB_INVALID_ARGUMENT) { @@ -514,11 +504,10 @@ static int compare_values(const grib_runtime_options* options, grib_handle* h1, return err; } - // if (options->mode != MODE_METAR) { + Assert(options->mode == MODE_METAR); // // TODO: Ignore missing values for keys in METAR. Not yet implemented // isMissing1 = ((grib_is_missing(h1, name, &err1) == 1) && (err1 == 0)) ? 1 : 0; // isMissing2 = ((grib_is_missing(h2, name, &err2) == 1) && (err2 == 0)) ? 1 : 0; - // } if ((isMissing1 == 1) && (isMissing2 == 1)) { if (verbose) @@ -746,8 +735,7 @@ static int compare_values(const grib_runtime_options* options, grib_handle* h1, break; case GRIB_TYPE_BYTES: - if (options->mode == MODE_METAR) - return 0; + return 0; // No such type for METAR break; case GRIB_TYPE_LABEL: