mirror of https://github.com/ecmwf/eccodes.git
Testing: codes_values_check (string and double)
This commit is contained in:
parent
5868eb2006
commit
ff4e751cf0
|
@ -16,9 +16,9 @@ int main(int argc, char* argv[])
|
||||||
char infile[] = "../../data/reduced_gaussian_model_level.grib1";
|
char infile[] = "../../data/reduced_gaussian_model_level.grib1";
|
||||||
codes_handle* h = NULL;
|
codes_handle* h = NULL;
|
||||||
codes_context* c = codes_context_get_default();
|
codes_context* c = codes_context_get_default();
|
||||||
codes_values values[2];
|
codes_values values[4];
|
||||||
int nvalues = 2;
|
const int nvalues = sizeof(values)/sizeof(values[0]);
|
||||||
int i;
|
int i = 0;
|
||||||
char* name = NULL;
|
char* name = NULL;
|
||||||
|
|
||||||
f = fopen(infile, "rb");
|
f = fopen(infile, "rb");
|
||||||
|
@ -34,30 +34,41 @@ int main(int argc, char* argv[])
|
||||||
}
|
}
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
values[0].type = CODES_TYPE_LONG;
|
values[i].type = CODES_TYPE_LONG;
|
||||||
values[0].name = "centre";
|
values[i].name = "centre";
|
||||||
values[0].long_value = 98;
|
values[i].long_value = 98;
|
||||||
|
i++;
|
||||||
|
|
||||||
values[1].type = CODES_TYPE_LONG;
|
values[i].type = CODES_TYPE_DOUBLE;
|
||||||
values[1].name = "level";
|
values[i].name = "bitsPerValue";
|
||||||
values[1].long_value = 2;
|
values[i].double_value = 13;
|
||||||
|
i++;
|
||||||
|
|
||||||
/*CODES_VALUE_DIFFERENT -> value is different*/
|
values[i].type = CODES_TYPE_STRING;
|
||||||
|
values[i].name = "identifier";
|
||||||
|
values[i].string_value = "GRIB";
|
||||||
|
i++;
|
||||||
|
|
||||||
|
values[i].type = CODES_TYPE_LONG;
|
||||||
|
values[i].name = "level";
|
||||||
|
values[i].long_value = 2; /* Intentionally made different; actual level==1 */
|
||||||
|
|
||||||
|
err = codes_values_check(h, values, nvalues);
|
||||||
|
if (err) {
|
||||||
|
for (i = 0; i < nvalues; i++) {
|
||||||
|
printf("i=%d %s\n",i, values[i].name);
|
||||||
|
if (values[i].error == err) name = (char*)values[i].name;
|
||||||
|
}
|
||||||
|
fprintf(stderr, "Error: \"%s\" - %s\n", name, codes_get_error_message(err));
|
||||||
|
}
|
||||||
|
|
||||||
|
values[1].name = "levelll"; /* non-existent key */
|
||||||
err = codes_values_check(h, values, nvalues);
|
err = codes_values_check(h, values, nvalues);
|
||||||
if (err) {
|
if (err) {
|
||||||
for (i = 0; i < nvalues; i++) {
|
for (i = 0; i < nvalues; i++) {
|
||||||
if (values[i].error == err) name = (char*)values[i].name;
|
if (values[i].error == err) name = (char*)values[i].name;
|
||||||
}
|
}
|
||||||
fprintf(stderr, "Error: \"%s\" %s\n", name, codes_get_error_message(err));
|
fprintf(stderr, "Error: \"%s\" - %s\n", name, codes_get_error_message(err));
|
||||||
}
|
|
||||||
|
|
||||||
values[1].name = "levelll";
|
|
||||||
err = codes_values_check(h, values, nvalues);
|
|
||||||
if (err) {
|
|
||||||
for (i = 0; i < nvalues; i++) {
|
|
||||||
if (values[i].error == err) name = (char*)values[i].name;
|
|
||||||
}
|
|
||||||
fprintf(stderr, "Error: \"%s\" %s\n", name, codes_get_error_message(err));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
codes_handle_delete(h);
|
codes_handle_delete(h);
|
||||||
|
|
|
@ -16,8 +16,8 @@ tempErr=${label}.tmp.err
|
||||||
tempRef=${label}.tmp.ref
|
tempRef=${label}.tmp.ref
|
||||||
|
|
||||||
cat > $tempRef <<EOF
|
cat > $tempRef <<EOF
|
||||||
Error: "level" Value is different
|
Error: "level" - Value is different
|
||||||
Error: "levelll" Key/value not found
|
Error: "levelll" - Key/value not found
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Input GRIB file path is hard coded in the example
|
# Input GRIB file path is hard coded in the example
|
||||||
|
|
Loading…
Reference in New Issue