Skip to content

Commit

Permalink
Tools: Dead code removal and cppcheck warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
shahramn committed Apr 9, 2024
1 parent f5c4b5d commit 7ff5e2e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 73 deletions.
21 changes: 10 additions & 11 deletions tools/grib_tools.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1339,16 +1339,15 @@ void grib_print_file_statistics(grib_runtime_options* options, grib_tools_file*
file->name);
if (!failed)
return;
/*
fprintf(dump_file,"Following bad messages found in %s\n", file->name);
fprintf(dump_file,"N Error\n");
while (failed){
fprintf(dump_file,"%-*d %s\n", 7,failed->count,
grib_get_error_message(failed->error));
failed=failed->next;
}
fprintf(dump_file,"\n");
*/

// fprintf(dump_file,"Following bad messages found in %s\n", file->name);
// fprintf(dump_file,"N Error\n");
// while (failed){
// fprintf(dump_file,"%-*d %s\n", 7,failed->count,
// grib_get_error_message(failed->error));
// failed=failed->next;
// }
// fprintf(dump_file,"\n");
}

void grib_print_full_statistics(grib_runtime_options* options)
Expand Down Expand Up @@ -1422,7 +1421,7 @@ void grib_tools_write_message(grib_runtime_options* options, grib_handle* h)
}

if (options->gts && h->gts_header) {
char gts_trailer[4] = { '\x0D', '\x0D', '\x0A', '\x03' };
const char gts_trailer[4] = { '\x0D', '\x0D', '\x0A', '\x03' };
if (fwrite(gts_trailer, 1, 4, of->handle) != 4) {
grib_context_log(h->context, (GRIB_LOG_ERROR) | (GRIB_LOG_PERROR),
"Error writing GTS trailer to %s", filename);
Expand Down
33 changes: 3 additions & 30 deletions tools/gts_compare.cc
Original file line number Diff line number Diff line change
Expand Up @@ -373,14 +373,11 @@ static void save_error(grib_context* c, const char* key)

static int compare_values(const grib_runtime_options* options, grib_handle* h1, grib_handle* h2, const char* name, int type)
{
size_t len1 = 0;
size_t len2 = 0;
int err = 0;
int err1;
int err2;
size_t len1 = 0, len2 = 0;
int err = 0, err1 = 0, err2 = 0;
int type1, type2;
int countdiff;
int isMissing1 = 0, isMissing2 = 0;
// int isMissing1 = 0, isMissing2 = 0;

char *sval1 = NULL, *sval2 = NULL;
long *lval1 = NULL, *lval2 = NULL;
Expand Down Expand Up @@ -442,30 +439,6 @@ static int compare_values(const grib_runtime_options* options, grib_handle* h1,
//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)
printf(" is set to missing in both fields\n");
return GRIB_SUCCESS;
}

if (isMissing1 == 1) {
if (verbose) printf(" is set to missing in 1st field\n");
printInfo(h1);
printf("%s is set to missing in 1st field but is not missing in 2nd field\n", name);
err1 = GRIB_VALUE_MISMATCH;
save_error(c, name);
return GRIB_VALUE_MISMATCH;
}

if (isMissing2 == 1) {
if (verbose) printf(" is set to missing in 1st field\n");
printInfo(h1);
printf("%s is set to missing in 2nd field but is not missing in 1st field\n", name);
err1 = GRIB_VALUE_MISMATCH;
save_error(c, name);
return GRIB_VALUE_MISMATCH;
}

switch (type1) {
case GRIB_TYPE_STRING:
if (verbose) printf(" as string\n");
Expand Down
36 changes: 4 additions & 32 deletions tools/metar_compare.cc
Original file line number Diff line number Diff line change
Expand Up @@ -426,19 +426,17 @@ static int compare_values(const grib_runtime_options* options, grib_handle* h1,
{
size_t len1 = 0;
size_t len2 = 0;
int err = 0, i = 0;
int err1;
int err2;
int err = 0, i = 0, err1 = 0, err2 = 0;
int type1, type2;
int countdiff;
int isMissing1 = 0, isMissing2 = 0;
//int isMissing1 = 0, isMissing2 = 0;

char *sval1 = NULL, *sval2 = NULL;
double *dval1 = NULL, *dval2 = NULL;
long *lval1 = NULL, *lval2 = NULL;
double maxdiff = 0;
double maxdiff = 0;
double value_tolerance = 0;
grib_context* c = h1->context;
grib_context* c = h1->context;

type1 = type;
type2 = type;
Expand Down Expand Up @@ -498,32 +496,6 @@ static int compare_values(const grib_runtime_options* options, grib_handle* h1,
// 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)
printf(" is set to missing in both fields\n");
return GRIB_SUCCESS;
}

if (isMissing1 == 1) {
if (verbose)
printf(" is set to missing in 1st field\n");
printInfo(h1);
printf("%s is set to missing in 1st field but is not missing in 2nd field\n", name);
err1 = GRIB_VALUE_MISMATCH;
save_error(c, name);
return GRIB_VALUE_MISMATCH;
}

if (isMissing2 == 1) {
if (verbose)
printf(" is set to missing in 1st field\n");
printInfo(h1);
printf("%s is set to missing in 2nd field but is not missing in 1st field\n", name);
err1 = GRIB_VALUE_MISMATCH;
save_error(c, name);
return GRIB_VALUE_MISMATCH;
}

switch (type1) {
case GRIB_TYPE_STRING:
if (verbose)
Expand Down

0 comments on commit 7ff5e2e

Please sign in to comment.