mirror of https://github.com/ecmwf/eccodes.git
Refactoring
This commit is contained in:
parent
9b2884d6ba
commit
bd3a25aaae
|
@ -10,6 +10,44 @@
|
|||
|
||||
#include "grib_tools.h"
|
||||
|
||||
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 },
|
||||
{ "2", 0, "Enable two-way comparison.\n", 0, 1, 0 },
|
||||
{ "T:", 0, 0, 1, 0, "B" },
|
||||
{ "c:", 0, 0, 0, 1, 0 },
|
||||
{ "S:", "start", "First field to be processed.\n", 0, 1, 0 },
|
||||
{ "E:", "end", "Last field to be processed.\n", 0, 1, 0 },
|
||||
{ "a", 0, "-c option modifier. The keys listed with the option -c will be added to the list of keys compared without -c.\n", 0, 1, 0 },
|
||||
{ "H", 0, "Compare only message headers. Bit-by-bit compare on. Incompatible with -c option.\n", 0, 1, 0 },
|
||||
{ "R:", 0, 0, 0, 1, 0 },
|
||||
{ "A:", 0, 0, 0, 1, 0 },
|
||||
/* {"P",0,"Compare data values using the packing error as tolerance.\n",0,1,0},*/
|
||||
{ "t:", "factor", "Compare data values using factor multiplied by the tolerance specified in options -R -A.\n", 0, 1, 0 },
|
||||
{ "w:", 0, 0, 0, 1, 0 },
|
||||
{ "f", 0, 0, 0, 1, 0 },
|
||||
{ "F", 0, 0, 1, 0, 0 },
|
||||
{ "q", 0, 0, 1, 0, 0 },
|
||||
{ "M", 0, 0, 1, 0, 0 },
|
||||
{ "I", 0, 0, 1, 0, 0 },
|
||||
{ "V", 0, 0, 0, 1, 0 },
|
||||
{ "7", 0, 0, 0, 1, 0 },
|
||||
{ "v", 0, 0, 0, 1, 0 }
|
||||
};
|
||||
|
||||
int grib_options_count = sizeof(grib_options) / sizeof(grib_option);
|
||||
|
||||
const char* tool_description =
|
||||
"Compare BUFR messages contained in two files."
|
||||
"\n\tIf some differences are found it fails returning an error code."
|
||||
"\n\tFloating-point values are compared exactly by default, different tolerances can be defined (see -A -R)."
|
||||
"\n\tDefault behaviour: absolute error=0, bit-by-bit compare, same order in files.";
|
||||
|
||||
const char* tool_name = "bufr_compare";
|
||||
const char* tool_usage = "[options] bufr_file1 bufr_file2";
|
||||
|
||||
GRIB_INLINE static int grib_inline_strcmp(const char* a, const char* b)
|
||||
{
|
||||
if (*a != *b)
|
||||
|
@ -21,25 +59,6 @@ GRIB_INLINE static int grib_inline_strcmp(const char* a, const char* b)
|
|||
return (*a == 0 && *b == 0) ? 0 : 1;
|
||||
}
|
||||
|
||||
GRIB_INLINE static int grib_inline_rstrcmp(const char* a, const char* b)
|
||||
{
|
||||
const char* p = a;
|
||||
const char* q = b;
|
||||
while (*p != 0)
|
||||
p++;
|
||||
while (*q != 0)
|
||||
q++;
|
||||
q--;
|
||||
p--;
|
||||
if (*q != *p)
|
||||
return 1;
|
||||
while ((p != a && q != b) && *(p) == *(q)) {
|
||||
p--;
|
||||
q--;
|
||||
}
|
||||
return (q == b) ? 0 : 1;
|
||||
}
|
||||
|
||||
typedef double (*compare_double_proc)(double*, double*, double*);
|
||||
|
||||
typedef struct grib_error grib_error;
|
||||
|
@ -60,9 +79,6 @@ static int isLeafKey = 0; /* 0 if key is top-level, 1 if key ha
|
|||
static int compareAbsolute = 1;
|
||||
|
||||
static int compare_handles(grib_handle* handle1, grib_handle* handle2, grib_runtime_options* options);
|
||||
static int compare_values(grib_runtime_options* options, grib_handle* handle1, grib_handle* handle2, const char* name, int type);
|
||||
static int compare_attributes(grib_handle* handle1, grib_handle* handle2, grib_runtime_options* options,
|
||||
grib_accessor* a, const char* prefix, int* err);
|
||||
static int compare_attribute(grib_handle* handle1, grib_handle* handle2, grib_runtime_options* options,
|
||||
grib_accessor* a, const char* prefix, int* err);
|
||||
|
||||
|
@ -88,6 +104,12 @@ static int listFromCommandLine;
|
|||
static int verbose = 0;
|
||||
static int tolerance_factor = 1;
|
||||
static int write_error = 0;
|
||||
static int write_count = 0;
|
||||
|
||||
static grib_handle* global_handle = NULL;
|
||||
static int counter = 0;
|
||||
static int start = -1;
|
||||
static int end = -1;
|
||||
|
||||
/* Create the list of keys (global variable keys_list) */
|
||||
static void new_keys_list()
|
||||
|
@ -125,8 +147,6 @@ GRIB_INLINE static double compare_double_absolute(double* a, double* b, double*
|
|||
/* return fabs(*a-*b) > *err ? fabs(*a-*b) : 0; */
|
||||
}
|
||||
|
||||
static int write_count = 0;
|
||||
|
||||
static void write_message(grib_handle* h, const char* str)
|
||||
{
|
||||
const void* m;
|
||||
|
@ -204,49 +224,6 @@ static double relative_error(double a, double b, double err)
|
|||
return relativeError;
|
||||
}
|
||||
|
||||
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 },
|
||||
{ "2", 0, "Enable two-way comparison.\n", 0, 1, 0 },
|
||||
{ "T:", 0, 0, 1, 0, "B" },
|
||||
{ "c:", 0, 0, 0, 1, 0 },
|
||||
{ "S:", "start", "First field to be processed.\n", 0, 1, 0 },
|
||||
{ "E:", "end", "Last field to be processed.\n", 0, 1, 0 },
|
||||
{ "a", 0, "-c option modifier. The keys listed with the option -c will be added to the list of keys compared without -c.\n", 0, 1, 0 },
|
||||
{ "H", 0, "Compare only message headers. Bit-by-bit compare on. Incompatible with -c option.\n", 0, 1, 0 },
|
||||
{ "R:", 0, 0, 0, 1, 0 },
|
||||
{ "A:", 0, 0, 0, 1, 0 },
|
||||
/* {"P",0,"Compare data values using the packing error as tolerance.\n",0,1,0},*/
|
||||
{ "t:", "factor", "Compare data values using factor multiplied by the tolerance specified in options -R -A.\n", 0, 1, 0 },
|
||||
{ "w:", 0, 0, 0, 1, 0 },
|
||||
{ "f", 0, 0, 0, 1, 0 },
|
||||
{ "F", 0, 0, 1, 0, 0 },
|
||||
{ "q", 0, 0, 1, 0, 0 },
|
||||
{ "M", 0, 0, 1, 0, 0 },
|
||||
{ "I", 0, 0, 1, 0, 0 },
|
||||
{ "V", 0, 0, 0, 1, 0 },
|
||||
{ "7", 0, 0, 0, 1, 0 },
|
||||
{ "v", 0, 0, 0, 1, 0 }
|
||||
};
|
||||
|
||||
static grib_handle* global_handle = NULL;
|
||||
static int counter = 0;
|
||||
static int start = -1;
|
||||
static int end = -1;
|
||||
|
||||
const char* tool_description =
|
||||
"Compare BUFR messages contained in two files."
|
||||
"\n\tIf some differences are found it fails returning an error code."
|
||||
"\n\tFloating-point values are compared exactly by default, different tolerances can be defined (see -A -R)."
|
||||
"\n\tDefault behaviour: absolute error=0, bit-by-bit compare, same order in files.";
|
||||
|
||||
const char* tool_name = "bufr_compare";
|
||||
const char* tool_usage = "[options] bufr_file1 bufr_file2";
|
||||
|
||||
int grib_options_count = sizeof(grib_options) / sizeof(grib_option);
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
return grib_tool(argc, argv);
|
||||
|
@ -696,7 +673,6 @@ static int compare_values(grib_runtime_options* options, grib_handle* handle1, g
|
|||
int err2;
|
||||
int type1, type2;
|
||||
int countdiff;
|
||||
int isangle = 0;
|
||||
int isMissing1 = 0, isMissing2 = 0;
|
||||
|
||||
char *sval1 = NULL, *sval2 = NULL;
|
||||
|
@ -928,37 +904,7 @@ static int compare_values(grib_runtime_options* options, grib_handle* handle1, g
|
|||
dval1 = (double*)grib_context_malloc(handle1->context, len1 * sizeof(double));
|
||||
dval2 = (double*)grib_context_malloc(handle2->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;
|
||||
packingError2 = 0;
|
||||
err1 = grib_get_double(handle1, "packingError", &packingError1);
|
||||
err2 = grib_get_double(handle2, "packingError", &packingError2);
|
||||
if (packingCompare)
|
||||
value_tolerance = packingError1 > packingError2 ? packingError1 : packingError2;
|
||||
}
|
||||
else if (!grib_inline_strcmp(name, "unpackedValues")) {
|
||||
packingError1 = 0;
|
||||
packingError2 = 0;
|
||||
err1 = grib_get_double(handle1, "unpackedError", &packingError1);
|
||||
err2 = grib_get_double(handle2, "unpackedError", &packingError2);
|
||||
if (packingCompare)
|
||||
value_tolerance = packingError1 > packingError2 ? packingError1 : packingError2;
|
||||
}
|
||||
else if (!grib_inline_rstrcmp(name, "InDegrees")) {
|
||||
packingError1 = 0.0005;
|
||||
packingError2 = 0.0005;
|
||||
isangle = 1;
|
||||
value_tolerance = packingError1 > packingError2 ? packingError1 : packingError2;
|
||||
}
|
||||
else if (!grib_inline_strcmp(name, "referenceValue")) {
|
||||
packingError1 = 0;
|
||||
packingError2 = 0;
|
||||
err1 = grib_get_double(handle1, "referenceValueError", &packingError1);
|
||||
err2 = grib_get_double(handle2, "referenceValueError", &packingError2);
|
||||
value_tolerance = packingError1 > packingError2 ? packingError1 : packingError2;
|
||||
}
|
||||
|
||||
if (!compareAbsolute) {
|
||||
int all_specified = 0; /* =1 if relative comparison with "all" specified */
|
||||
|
@ -1012,13 +958,13 @@ static int compare_values(grib_runtime_options* options, grib_handle* handle1, g
|
|||
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) {
|
||||
/* if (isangle) {
|
||||
dnew1 = *dval1;
|
||||
dnew2 = *dval2;
|
||||
pv1 = &dnew1;
|
||||
|
@ -1031,7 +977,7 @@ static int compare_values(grib_runtime_options* options, grib_handle* handle1, g
|
|||
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);
|
||||
|
@ -1073,14 +1019,6 @@ static int compare_values(grib_runtime_options* options, grib_handle* handle1, g
|
|||
if (packingError2 != 0 || packingError1 != 0)
|
||||
printf(" packingError: [%g] [%g]", packingError1, packingError2);
|
||||
|
||||
if (!grib_inline_strcmp(name, "packedValues") || !grib_inline_strcmp(name, "values") || !grib_inline_strcmp(name, "codedValues")) {
|
||||
double max1, min1, max2, min2;
|
||||
grib_get_double(handle1, "max", &max1);
|
||||
grib_get_double(handle1, "min", &min1);
|
||||
grib_get_double(handle2, "max", &max2);
|
||||
grib_get_double(handle2, "min", &min2);
|
||||
printf("\n\tvalues max= [%g] [%g] min= [%g] [%g]", max1, max2, min1, min2);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -82,9 +82,9 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
|
|||
grib_values* values = NULL;
|
||||
grib_iterator* iter = NULL;
|
||||
char* format_values = NULL;
|
||||
char format_latlons[64] = {0,};
|
||||
char format_latlons[32] = {0,};
|
||||
char* default_format_values = "%.10e";
|
||||
char* default_format_latlons = "%9.3f%9.3f ";
|
||||
char* default_format_latlons = "%9.3f%9.3f";
|
||||
int print_keys = grib_options_on("p:");
|
||||
long numberOfPoints = 0;
|
||||
long bitmapPresent = 0;
|
||||
|
@ -133,21 +133,20 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
|
|||
|
||||
if (grib_options_on("L:")) {
|
||||
/* Do a very basic sanity check */
|
||||
size_t ii=0, count=0;
|
||||
const char* str = grib_options_get_option("L:");
|
||||
for(ii=0; str[ii]; ii++) if (str[ii] == '%') count++;
|
||||
if (count != 2) {
|
||||
fprintf(stderr, "ERROR: Invalid lats/lons format option \"%s\"\n", str);
|
||||
return err;
|
||||
if (count_char_in_string(str, '%') != 2) {
|
||||
fprintf(stderr, "ERROR: Invalid lats/lons format option \"%s\".\nThe default is: \"%s\"\n",
|
||||
str, default_format_latlons);
|
||||
exit(1);
|
||||
}
|
||||
sprintf(format_latlons, "%s ", grib_options_get_option("L:"));/*Add a final space to separate from data values*/
|
||||
sprintf(format_latlons, "%s ", str);/* Add a final space to separate from data values */
|
||||
} else {
|
||||
sprintf(format_latlons, "%s", default_format_latlons);
|
||||
sprintf(format_latlons, "%s ", default_format_latlons);
|
||||
}
|
||||
|
||||
if ((err = grib_get_long(h, "numberOfPoints", &numberOfPoints)) != GRIB_SUCCESS) {
|
||||
fprintf(stderr, "ERROR: unable to get number of points\n");
|
||||
return err;
|
||||
fprintf(stderr, "ERROR: Unable to get number of points\n");
|
||||
exit(err);
|
||||
}
|
||||
|
||||
iter = grib_iterator_new(h, 0, &err);
|
||||
|
@ -155,7 +154,7 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
|
|||
num_bytes = (numberOfPoints + 1) * sizeof(double);
|
||||
data_values = (double*)calloc(numberOfPoints + 1, sizeof(double));
|
||||
if (!data_values) {
|
||||
fprintf(stderr, "ERROR: failed to allocate %ld bytes for data values (number of points=%ld)\n",
|
||||
fprintf(stderr, "ERROR: Failed to allocate %ld bytes for data values (number of points=%ld)\n",
|
||||
(long)num_bytes, numberOfPoints);
|
||||
exit(GRIB_OUT_OF_MEMORY);
|
||||
}
|
||||
|
@ -179,7 +178,7 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
|
|||
}
|
||||
if (size != numberOfPoints) {
|
||||
if (!grib_options_on("q"))
|
||||
fprintf(stderr, "ERROR: wrong number of points %d\n", (int)numberOfPoints);
|
||||
fprintf(stderr, "ERROR: Wrong number of points %d\n", (int)numberOfPoints);
|
||||
if (grib_options_on("f"))
|
||||
exit(1);
|
||||
}
|
||||
|
|
|
@ -10,6 +10,42 @@
|
|||
|
||||
#include "grib_tools.h"
|
||||
|
||||
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, "T" }, /* GTS */
|
||||
{ "c:", 0, 0, 0, 1, 0 },
|
||||
{ "S:", "start", "First field to be processed.\n", 0, 1, 0 },
|
||||
{ "E:", "end", "Last field to be processed.\n", 0, 1, 0 },
|
||||
{ "a", 0, "-c option modifier. The keys listed with the option -c will be added to the list of keys compared without -c.\n", 0, 1, 0 },
|
||||
/*{"H",0,"Compare only message headers. Bit-by-bit compare on. Incompatible with -c option.\n",0,1,0},*/
|
||||
/*{"R:",0,0,0,1,0},*/
|
||||
/*{"A:",0,0,0,1,0},*/
|
||||
{ "w:", 0, 0, 0, 1, 0 },
|
||||
{ "f", 0, 0, 0, 1, 0 },
|
||||
{ "F", 0, 0, 1, 0, 0 },
|
||||
{ "q", 0, 0, 1, 0, 0 },
|
||||
{ "I", 0, 0, 1, 0, 0 },
|
||||
{ "V", 0, 0, 0, 1, 0 },
|
||||
{ "7", 0, 0, 0, 1, 0 },
|
||||
{ "v", 0, 0, 0, 1, 0 }
|
||||
};
|
||||
|
||||
int grib_options_count = sizeof(grib_options) / sizeof(grib_option);
|
||||
|
||||
const char* tool_description =
|
||||
"Compare GTS messages contained in two files."
|
||||
"\n\tIf some differences are found it fails returning an error code."
|
||||
"\n\tDefault behaviour: bit-by-bit compare, same order in files.";
|
||||
|
||||
const char* tool_name = "gts_compare";
|
||||
const char* tool_usage =
|
||||
"[options] "
|
||||
"file file";
|
||||
|
||||
|
||||
GRIB_INLINE static int grib_inline_strcmp(const char* a, const char* b)
|
||||
{
|
||||
if (*a != *b)
|
||||
|
@ -37,7 +73,7 @@ compare_double_proc compare_double;
|
|||
grib_string_list* blocklist = 0;
|
||||
|
||||
static int compare_handles(grib_handle* h1, grib_handle* h2, grib_runtime_options* options);
|
||||
static int compare_values(grib_runtime_options* options, grib_handle* h1, grib_handle* h2, const char* name, int type);
|
||||
|
||||
int error = 0;
|
||||
int count = 0;
|
||||
int lastPrint = 0;
|
||||
|
@ -54,6 +90,12 @@ static int write_error = 0;
|
|||
|
||||
static int write_count = 0;
|
||||
|
||||
grib_handle* global_handle = NULL;
|
||||
int counter = 0;
|
||||
int start = -1;
|
||||
int end = -1;
|
||||
|
||||
|
||||
static void write_message(grib_handle* h, const char* str)
|
||||
{
|
||||
const void* m;
|
||||
|
@ -103,46 +145,6 @@ static int blocklisted(const char* name)
|
|||
return 0;
|
||||
}
|
||||
|
||||
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, "T" }, /* GTS */
|
||||
{ "c:", 0, 0, 0, 1, 0 },
|
||||
{ "S:", "start", "First field to be processed.\n", 0, 1, 0 },
|
||||
{ "E:", "end", "Last field to be processed.\n", 0, 1, 0 },
|
||||
{ "a", 0, "-c option modifier. The keys listed with the option -c will be added to the list of keys compared without -c.\n", 0, 1, 0 },
|
||||
/*{"H",0,"Compare only message headers. Bit-by-bit compare on. Incompatible with -c option.\n",0,1,0},*/
|
||||
/*{"R:",0,0,0,1,0},*/
|
||||
/*{"A:",0,0,0,1,0},*/
|
||||
{ "w:", 0, 0, 0, 1, 0 },
|
||||
{ "f", 0, 0, 0, 1, 0 },
|
||||
{ "F", 0, 0, 1, 0, 0 },
|
||||
{ "q", 0, 0, 1, 0, 0 },
|
||||
{ "I", 0, 0, 1, 0, 0 },
|
||||
{ "V", 0, 0, 0, 1, 0 },
|
||||
{ "7", 0, 0, 0, 1, 0 },
|
||||
{ "v", 0, 0, 0, 1, 0 }
|
||||
};
|
||||
|
||||
grib_handle* global_handle = NULL;
|
||||
int counter = 0;
|
||||
int start = -1;
|
||||
int end = -1;
|
||||
|
||||
const char* tool_description =
|
||||
"Compare GTS messages contained in two files."
|
||||
"\n\tIf some differences are found it fails returning an error code."
|
||||
"\n\tDefault behaviour: bit-by-bit compare, same order in files.";
|
||||
|
||||
const char* tool_name = "gts_compare";
|
||||
const char* tool_usage =
|
||||
"[options] "
|
||||
"file file";
|
||||
|
||||
int grib_options_count = sizeof(grib_options) / sizeof(grib_option);
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
return grib_tool(argc, argv);
|
||||
|
|
|
@ -10,6 +10,45 @@
|
|||
|
||||
#include "grib_tools.h"
|
||||
|
||||
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 */
|
||||
{ "c:", 0, 0, 0, 1, 0 },
|
||||
{ "S:", "start", "First field to be processed.\n", 0, 1, 0 },
|
||||
{ "E:", "end", "Last field to be processed.\n", 0, 1, 0 },
|
||||
{ "a", 0, "-c option modifier. The keys listed with the option -c will be added to the list of keys compared without -c.\n", 0, 1, 0 },
|
||||
{ "H", 0, "Compare only message headers. Bit-by-bit compare on. Incompatible with -c option.\n", 0, 1, 0 },
|
||||
{ "R:", 0, 0, 0, 1, 0 },
|
||||
{ "A:", 0, 0, 0, 1, 0 },
|
||||
{ "P", 0, "Compare data values using the packing error as tolerance.\n", 0, 1, 0 },
|
||||
{ "t:", "factor", "Compare data values using factor multiplied by the tolerance specified in options -P -R -A.\n", 0, 1, 0 },
|
||||
{ "w:", 0, 0, 0, 1, 0 },
|
||||
{ "f", 0, 0, 0, 1, 0 },
|
||||
{ "F", 0, 0, 1, 0, 0 },
|
||||
{ "q", 0, 0, 1, 0, 0 },
|
||||
{ "I", 0, 0, 1, 0, 0 },
|
||||
{ "V", 0, 0, 0, 1, 0 },
|
||||
{ "7", 0, 0, 0, 1, 0 },
|
||||
{ "v", 0, 0, 0, 1, 0 }
|
||||
};
|
||||
|
||||
int grib_options_count = sizeof(grib_options) / sizeof(grib_option);
|
||||
|
||||
const char* tool_description =
|
||||
"Compare METAR messages contained in two files."
|
||||
"\n\tIf some differences are found it fails returning an error code."
|
||||
"\n\tFloating-point values are compared exactly by default, different tolerance can be defined see -P -A -R."
|
||||
"\n\tDefault behaviour: absolute error=0, bit-by-bit compare, same order in files.";
|
||||
|
||||
const char* tool_name = "metar_compare";
|
||||
const char* tool_usage =
|
||||
"[options] "
|
||||
"file file";
|
||||
|
||||
|
||||
GRIB_INLINE static int grib_inline_strcmp(const char* a, const char* b)
|
||||
{
|
||||
if (*a != *b)
|
||||
|
@ -21,25 +60,6 @@ GRIB_INLINE static int grib_inline_strcmp(const char* a, const char* b)
|
|||
return (*a == 0 && *b == 0) ? 0 : 1;
|
||||
}
|
||||
|
||||
GRIB_INLINE static int grib_inline_rstrcmp(const char* a, const char* b)
|
||||
{
|
||||
char* p = (char*)a;
|
||||
char* q = (char*)b;
|
||||
while (*p != 0)
|
||||
p++;
|
||||
while (*q != 0)
|
||||
q++;
|
||||
q--;
|
||||
p--;
|
||||
if (*q != *p)
|
||||
return 1;
|
||||
while ((p != a && q != b) && *(p) == *(q)) {
|
||||
p--;
|
||||
q--;
|
||||
}
|
||||
return (q == b) ? 0 : 1;
|
||||
}
|
||||
|
||||
typedef double (*compare_double_proc)(double*, double*, double*);
|
||||
|
||||
typedef struct grib_error grib_error;
|
||||
|
@ -50,29 +70,32 @@ struct grib_error
|
|||
grib_error* next;
|
||||
};
|
||||
|
||||
grib_error* error_summary;
|
||||
|
||||
compare_double_proc compare_double;
|
||||
double global_tolerance = 0;
|
||||
int packingCompare = 0;
|
||||
grib_string_list* blocklist = 0;
|
||||
int compareAbsolute = 1;
|
||||
static grib_error* error_summary;
|
||||
static compare_double_proc compare_double;
|
||||
static double global_tolerance = 0;
|
||||
static int packingCompare = 0;
|
||||
static grib_string_list* blocklist = 0;
|
||||
static int compareAbsolute = 1;
|
||||
|
||||
static int compare_handles(grib_handle* h1, grib_handle* h2, grib_runtime_options* options);
|
||||
static int compare_values(grib_runtime_options* options, grib_handle* h1, grib_handle* h2, const char* name, int type);
|
||||
int error = 0;
|
||||
int count = 0;
|
||||
int lastPrint = 0;
|
||||
int force = 0;
|
||||
double maxAbsoluteError = 1e-19;
|
||||
int onlyListed = 1;
|
||||
int headerMode = 0;
|
||||
int morein1 = 0;
|
||||
int morein2 = 0;
|
||||
int listFromCommandLine;
|
||||
int verbose = 0;
|
||||
int tolerance_factor = 1;
|
||||
static int error = 0;
|
||||
static int count = 0;
|
||||
static int lastPrint = 0;
|
||||
static int force = 0;
|
||||
static double maxAbsoluteError = 1e-19;
|
||||
static int onlyListed = 1;
|
||||
static int headerMode = 0;
|
||||
static int morein1 = 0;
|
||||
static int morein2 = 0;
|
||||
static int listFromCommandLine;
|
||||
static int verbose = 0;
|
||||
static int 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;
|
||||
|
||||
GRIB_INLINE static double compare_double_absolute(double* a, double* b, double* err)
|
||||
{
|
||||
|
@ -85,8 +108,6 @@ GRIB_INLINE static double compare_double_absolute(double* a, double* b, double*
|
|||
/* return fabs(*a-*b) > *err ? fabs(*a-*b) : 0; */
|
||||
}
|
||||
|
||||
static int write_count = 0;
|
||||
|
||||
static void write_message(grib_handle* h, const char* str)
|
||||
{
|
||||
const void* m;
|
||||
|
@ -164,49 +185,6 @@ static double relative_error(double a, double b, double err)
|
|||
return relativeError;
|
||||
}
|
||||
|
||||
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 */
|
||||
{ "c:", 0, 0, 0, 1, 0 },
|
||||
{ "S:", "start", "First field to be processed.\n", 0, 1, 0 },
|
||||
{ "E:", "end", "Last field to be processed.\n", 0, 1, 0 },
|
||||
{ "a", 0, "-c option modifier. The keys listed with the option -c will be added to the list of keys compared without -c.\n", 0, 1, 0 },
|
||||
{ "H", 0, "Compare only message headers. Bit-by-bit compare on. Incompatible with -c option.\n", 0, 1, 0 },
|
||||
{ "R:", 0, 0, 0, 1, 0 },
|
||||
{ "A:", 0, 0, 0, 1, 0 },
|
||||
{ "P", 0, "Compare data values using the packing error as tolerance.\n", 0, 1, 0 },
|
||||
{ "t:", "factor", "Compare data values using factor multiplied by the tolerance specified in options -P -R -A.\n", 0, 1, 0 },
|
||||
{ "w:", 0, 0, 0, 1, 0 },
|
||||
{ "f", 0, 0, 0, 1, 0 },
|
||||
{ "F", 0, 0, 1, 0, 0 },
|
||||
{ "q", 0, 0, 1, 0, 0 },
|
||||
{ "I", 0, 0, 1, 0, 0 },
|
||||
{ "V", 0, 0, 0, 1, 0 },
|
||||
{ "7", 0, 0, 0, 1, 0 },
|
||||
{ "v", 0, 0, 0, 1, 0 }
|
||||
};
|
||||
|
||||
grib_handle* global_handle = NULL;
|
||||
int global_counter = 0;
|
||||
int start = -1;
|
||||
int end = -1;
|
||||
|
||||
const char* tool_description =
|
||||
"Compare METAR messages contained in two files."
|
||||
"\n\tIf some differences are found it fails returning an error code."
|
||||
"\n\tFloating-point values are compared exactly by default, different tolerance can be defined see -P -A -R."
|
||||
"\n\tDefault behaviour: absolute error=0, bit-by-bit compare, same order in files.";
|
||||
|
||||
const char* tool_name = "metar_compare";
|
||||
const char* tool_usage =
|
||||
"[options] "
|
||||
"file file";
|
||||
|
||||
int grib_options_count = sizeof(grib_options) / sizeof(grib_option);
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
return grib_tool(argc, argv);
|
||||
|
@ -817,12 +795,6 @@ static int compare_values(grib_runtime_options* options, grib_handle* h1, grib_h
|
|||
if (packingCompare)
|
||||
value_tolerance = packingError1 > packingError2 ? packingError1 : packingError2;
|
||||
}
|
||||
else if (!grib_inline_rstrcmp(name, "InDegrees")) {
|
||||
packingError1 = 0.0005;
|
||||
packingError2 = 0.0005;
|
||||
isangle = 1;
|
||||
value_tolerance = packingError1 > packingError2 ? packingError1 : packingError2;
|
||||
}
|
||||
else if (!grib_inline_strcmp(name, "referenceValue")) {
|
||||
packingError1 = 0;
|
||||
packingError2 = 0;
|
||||
|
|
Loading…
Reference in New Issue