Tools: Dead code removal

This commit is contained in:
Shahram Najm 2023-08-11 21:57:13 +01:00
parent 94b428d997
commit 774dbab5ec
2 changed files with 18 additions and 220 deletions

View File

@ -42,9 +42,7 @@ const char* tool_description =
const char* tool_name = "gts_compare";
const char* tool_online_doc = NULL;
const char* tool_usage =
"[options] "
"file file";
const char* tool_usage = "[options] file file";
GRIB_INLINE static int grib_inline_strcmp(const char* a, const char* b)
@ -157,9 +155,6 @@ int grib_tool_before_getopt(grib_runtime_options* options)
int grib_tool_init(grib_runtime_options* options)
{
int ret = 0;
int nfiles = 1;
char orderby[] = "md5Headers";
grib_context* context = grib_context_get_default();
options->strict = 1;
@ -218,20 +213,6 @@ int grib_tool_init(grib_runtime_options* options)
context->blocklist = blocklist;
}
if (grib_options_on("r")) {
const char* filename[1];
filename[0] = options->infile_extra->name;
options->random = 1;
options->orderby = strdup(orderby);
options->idx = grib_fieldset_new_from_files(context, filename,
nfiles, 0, 0, 0, orderby, &ret);
if (ret) {
printf("unable to create index for input file %s (%s)",
options->infile_extra->name, grib_get_error_message(ret));
exit(ret);
}
}
else {
options->random = 0;
options->infile_extra->file = fopen(options->infile_extra->name, "r");
@ -239,7 +220,6 @@ int grib_tool_init(grib_runtime_options* options)
perror(options->infile_extra->name);
exit(1);
}
}
if (grib_options_on("t:"))
tolerance_factor = atof(grib_options_get_option("t:"));
@ -279,19 +259,6 @@ static void printInfo(grib_handle* h)
lastPrint = count;
}
static void print_index_key_values(grib_index* index, int cnt, const char* error_message)
{
grib_index_key* keys = index->keys;
printf("== %d == ", cnt);
if (error_message)
printf("%s == ", error_message);
while (keys) {
printf("%s=%s ", keys->name, keys->value);
keys = keys->next;
}
printf("\n");
}
static grib_handle* gts_handle_new_from_file_x(
grib_context* c, FILE* f, int mode, int headers_only, int* err)
{
@ -303,51 +270,7 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
int err = 0;
count++;
if (options->through_index) {
grib_index* idx1 = options->index1;
verbose = 0;
counter++;
if (start > 0 && counter < start)
return 0;
if (end > 0 && counter > end) {
options->stop = 1;
return 0;
}
grib_index_search_same(idx1, h);
global_handle = codes_new_from_index(idx1, CODES_GTS, &err);
if (options->verbose) {
off_t offset = 0;
char* filename = grib_get_field_file(options->index2, &offset);
printf("file1=\"%s\" ", filename);
filename = grib_get_field_file(options->index1, &offset);
printf("file2=\"%s\" \n", filename);
print_index_key_values(options->index1, counter, NULL);
}
if (!global_handle) {
if (!options->verbose)
print_index_key_values(idx1, counter, "NOT FOUND ");
}
if (!global_handle || err != GRIB_SUCCESS) {
morein1++;
grib_handle_delete(global_handle);
return 0;
}
if (compare_handles(h, global_handle, options)) {
error++;
if (!force)
exit(1);
}
grib_handle_delete(global_handle);
return 0;
}
else if (options->random)
if (options->random)
global_handle = grib_fieldset_next_handle(options->idx, &err);
else
global_handle = gts_handle_new_from_file_x(h->context, options->infile_extra->file, options->mode, 0, &err);
@ -430,10 +353,6 @@ int grib_tool_finalise_action(grib_runtime_options* options)
printf("##\n## %d different messages out of %d\n\n", error, count);
}
if (options->through_index) {
grib_index_delete(options->index1);
grib_index_delete(options->index2);
}
if (error != 0)
exit(1);

View File

@ -12,7 +12,6 @@
grib_option grib_options[] = {
/* {id, args, help}, on, command_line, value*/
{ "r", 0, "Compare files in which the messages are not in the same order. This option is time expensive.\n", 0, 1, 0 },
{ "b:", 0, 0, 0, 1, 0 },
{ "d", 0, "Write different messages on files\n", 0, 1, 0 },
{ "T:", 0, 0, 1, 0, "M" }, /* METAR */
@ -44,9 +43,7 @@ const char* tool_description =
const char* tool_name = "metar_compare";
const char* tool_online_doc = NULL;
const char* tool_usage =
"[options] "
"file file";
const char* tool_usage = "[options] file file";
GRIB_INLINE static int grib_inline_strcmp(const char* a, const char* b)
@ -91,7 +88,6 @@ static int verbose = 0;
static double tolerance_factor = 1;
static int write_error = 0;
static grib_handle* global_handle = NULL;
static int global_counter = 0;
static int start = -1;
static int end = -1;
static int write_count = 0;
@ -196,9 +192,6 @@ int grib_tool_before_getopt(grib_runtime_options* options)
int grib_tool_init(grib_runtime_options* options)
{
int ret = 0, i;
int nfiles = 1;
char orderby[] = "md5Headers";
grib_context* context = grib_context_get_default();
options->strict = 1;
@ -243,7 +236,7 @@ int grib_tool_init(grib_runtime_options* options)
blocklist = (grib_string_list*)grib_context_malloc_clear(context, sizeof(grib_string_list));
blocklist->value = grib_context_strdup(context, options->set_values[0].name);
next = blocklist;
for (i = 1; i < options->set_values_count; i++) {
for (int i = 1; i < options->set_values_count; i++) {
next->next = (grib_string_list*)grib_context_malloc_clear(context, sizeof(grib_string_list));
next->next->value = grib_context_strdup(context, options->set_values[i].name);
next = next->next;
@ -251,20 +244,6 @@ int grib_tool_init(grib_runtime_options* options)
context->blocklist = blocklist;
}
if (grib_options_on("r")) {
const char* filename[1];
filename[0] = options->infile_extra->name;
options->random = 1;
options->orderby = strdup(orderby);
options->idx = grib_fieldset_new_from_files(context, filename,
nfiles, 0, 0, 0, orderby, &ret);
if (ret) {
printf("unable to create index for input file %s (%s)",
options->infile_extra->name, grib_get_error_message(ret));
exit(ret);
}
}
else {
options->random = 0;
options->infile_extra->file = fopen(options->infile_extra->name, "r");
@ -272,13 +251,12 @@ int grib_tool_init(grib_runtime_options* options)
perror(options->infile_extra->name);
exit(1);
}
}
global_tolerance = 0;
compare_double = &compare_double_absolute;
if (grib_options_on("R:")) {
global_tolerance = 0;
for (i = 0; i < options->tolerance_count; i++) {
for (int i = 0; i < options->tolerance_count; i++) {
if (!strcmp((options->tolerance[i]).name, "all")) {
global_tolerance = (options->tolerance[i]).double_value;
break;
@ -344,21 +322,7 @@ static void printInfo(grib_handle* h)
lastPrint = count;
}
static void print_index_key_values(grib_index* index, int counter, const char* error_message)
{
grib_index_key* keys = index->keys;
printf("== %d == ", counter);
if (error_message)
printf("%s == ", error_message);
while (keys) {
printf("%s=%s ", keys->name, keys->value);
keys = keys->next;
}
printf("\n");
}
static grib_handle* metar_handle_new_from_file_x(
grib_context* c, FILE* f, int mode, int headers_only, int* err)
static grib_handle* metar_handle_new_from_file_x(grib_context* c, FILE* f, int mode, int headers_only, int* err)
{
return codes_handle_new_from_file(c, f, PRODUCT_METAR, err);
}
@ -368,52 +332,7 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
int err = 0;
count++;
if (options->through_index) {
grib_index* idx1 = options->index1;
verbose = 0;
global_counter++;
if (start > 0 && global_counter < start)
return 0;
if (end > 0 && global_counter > end) {
options->stop = 1;
return 0;
}
grib_index_search_same(idx1, h);
global_handle = codes_new_from_index(idx1, CODES_METAR, &err);
if (options->verbose) {
off_t offset = 0;
char* filename = grib_get_field_file(options->index2, &offset);
printf("file1=\"%s\" ", filename);
filename = grib_get_field_file(options->index1, &offset);
printf("file2=\"%s\" \n", filename);
print_index_key_values(options->index1, global_counter, NULL);
}
if (!global_handle) {
if (!options->verbose)
print_index_key_values(idx1, global_counter, "NOT FOUND ");
}
if (!global_handle || err != GRIB_SUCCESS) {
morein1++;
if (global_handle)
grib_handle_delete(global_handle);
return 0;
}
if (compare_handles(h, global_handle, options)) {
error++;
if (!force)
exit(1);
}
grib_handle_delete(global_handle);
return 0;
}
else if (options->random)
if (options->random)
global_handle = grib_fieldset_next_handle(options->idx, &err);
else
global_handle = metar_handle_new_from_file_x(h->context, options->infile_extra->file, options->mode, 0, &err);
@ -496,10 +415,6 @@ int grib_tool_finalise_action(grib_runtime_options* options)
printf("##\n## %d different messages out of %d\n\n", error, count);
}
if (options->through_index) {
grib_index_delete(options->index1);
grib_index_delete(options->index2);
}
if (error != 0)
exit(1);
@ -548,7 +463,6 @@ static int compare_values(grib_runtime_options* options, grib_handle* h1, grib_h
int err2;
int type1, type2;
int countdiff;
int isangle = 0;
int isMissing1 = 0, isMissing2 = 0;
char *sval1 = NULL, *sval2 = NULL;
@ -585,16 +499,6 @@ static int compare_values(grib_runtime_options* options, grib_handle* h1, grib_h
return err;
}
/*
if(type1 != type2)
{
printInfo(h1);
printf("Warning, [%s] has different types: 1st field: [%s], 2nd field: [%s]\n",
name,grib_get_type_name(type1),grib_get_type_name(type2));
return GRIB_TYPE_MISMATCH;
}
*/
if (type1 == GRIB_TYPE_LABEL)
return err;
@ -623,16 +527,6 @@ static int compare_values(grib_runtime_options* options, grib_handle* h1, grib_h
return err;
}
/*
if(len1 != len2 && type1 != GRIB_TYPE_STRING)
{
printInfo(h1);
printf("[%s] has different size: 1st field: %ld, 2nd field: %ld\n",name,(long)len1,(long)len2);
save_error(c,name);
return GRIB_COUNT_MISMATCH;
}
*/
if (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;
@ -770,7 +664,6 @@ static int compare_values(grib_runtime_options* options, grib_handle* h1, grib_h
dval1 = (double*)grib_context_malloc(h1->context, len1 * sizeof(double));
dval2 = (double*)grib_context_malloc(h2->context, len2 * sizeof(double));
isangle = 0;
value_tolerance = global_tolerance;
if (!grib_inline_strcmp(name, "packedValues") || !grib_inline_strcmp(name, "values") || !grib_inline_strcmp(name, "codedValues")) {
packingError1 = 0;
@ -835,26 +728,12 @@ static int compare_values(grib_runtime_options* options, grib_handle* h1, grib_h
if (err1 == GRIB_SUCCESS && err2 == GRIB_SUCCESS && len1 == len2) {
int imaxdiff;
double diff;
double *pv1, *pv2, dnew1, dnew2;
double *pv1, *pv2;
maxdiff = 0;
imaxdiff = 0;
countdiff = 0;
pv1 = dval1;
pv2 = dval2;
if (isangle) {
dnew1 = *dval1;
dnew2 = *dval2;
pv1 = &dnew1;
pv2 = &dnew2;
if (*dval1 < 0)
dnew1 += 360.0;
if (*dval2 < 0)
dnew2 += 360.0;
if (*dval1 > 360)
dnew1 -= 360.0;
if (*dval2 > 360)
dnew2 -= 360.0;
}
value_tolerance *= tolerance_factor;
if (verbose)
printf(" (%d values) tolerance=%g\n", (int)len1, value_tolerance);