mirror of https://github.com/ecmwf/eccodes.git
ECC-401: Add test for bufr_ls and fix numeric values
This commit is contained in:
parent
7c2a2a70a1
commit
8639037a85
|
@ -87,6 +87,7 @@ list( APPEND tests_data_reqd
|
|||
bufr_filter_extract_area
|
||||
bufr_json_data
|
||||
bufr_ls
|
||||
bufr_ls_json
|
||||
bufr_change_edition
|
||||
bufr_keys_iter
|
||||
bufr_get_element
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
#!/bin/sh
|
||||
# Copyright 2005-2019 ECMWF.
|
||||
#
|
||||
# This software is licensed under the terms of the Apache Licence Version 2.0
|
||||
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
|
||||
#
|
||||
# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
|
||||
# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
|
||||
#
|
||||
|
||||
. ./include.sh
|
||||
|
||||
tempLog=temp.bufr_ls_json.log
|
||||
rm -f $tempLog
|
||||
|
||||
cd ${data_dir}/bufr
|
||||
|
||||
# Check JSON validity
|
||||
# --------------------
|
||||
# Decide if we have the JSON verifier commandline utility
|
||||
JSON_VERIF="json_xs"
|
||||
JSON_CHECK=""
|
||||
if command -v $JSON_VERIF >/dev/null 2>&1; then
|
||||
JSON_CHECK=$JSON_VERIF
|
||||
fi
|
||||
|
||||
bufr_files=`cat bufr_data_files.txt`
|
||||
for file in ${bufr_files}
|
||||
do
|
||||
${tools_dir}/bufr_ls -j $file > $tempLog
|
||||
if test "x$JSON_CHECK" != "x"; then
|
||||
# TODO: Keys like typicalDate/rdbtimeDate can have
|
||||
# values like 00121102 or 000000.
|
||||
# JSON check will fail: malformed number (leading zero must not be followed by another digit)
|
||||
cat $tempLog | sed '/: 0[0-9]/d' | json_xs -t none
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
# Clean up
|
||||
rm -f $tempLog
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
. ./include.sh
|
||||
|
||||
tempLog=temp.ls.json.log
|
||||
tempLog=temp.grib_ls_json.log
|
||||
rm -f $tempLog
|
||||
|
||||
cd ${data_dir}
|
||||
|
@ -19,15 +19,25 @@ cd ${data_dir}
|
|||
# --------------------
|
||||
input=sample.grib2
|
||||
${tools_dir}/grib_ls -j -p scaledValueOfEarthMajorAxis $input > $tempLog
|
||||
grep -q "scaledValueOfEarthMajorAxis.*MISSING" $tempLog
|
||||
grep -q '"scaledValueOfEarthMajorAxis": "MISSING"' $tempLog
|
||||
|
||||
|
||||
# Test decoding a given key in different ways
|
||||
# Test decoding a given key as string and integer
|
||||
# ---------------------------------------------
|
||||
input=$ECCODES_SAMPLES_PATH/GRIB1.tmpl
|
||||
${tools_dir}/grib_ls -j -p levelType,levelType:i $input > $tempLog
|
||||
grep -q "levelType.*pl" $tempLog
|
||||
grep -q "levelType.*100" $tempLog
|
||||
grep -q '"levelType": "pl"' $tempLog
|
||||
grep -q '"levelType": 100' $tempLog
|
||||
|
||||
|
||||
# Test decoding floating point key with format
|
||||
# ---------------------------------------------
|
||||
input=$ECCODES_SAMPLES_PATH/reduced_gg_pl_128_grib2.tmpl
|
||||
${tools_dir}/grib_ls -j -p latitudeOfLastGridPointInDegrees $input > $tempLog
|
||||
grep -q '"latitudeOfLastGridPointInDegrees": -89.4628' $tempLog
|
||||
|
||||
${tools_dir}/grib_ls -F%.3f -j -p latitudeOfLastGridPointInDegrees $input > $tempLog
|
||||
grep -q '"latitudeOfLastGridPointInDegrees": -89.463' $tempLog
|
||||
|
||||
|
||||
# Check JSON validity
|
||||
|
|
|
@ -102,7 +102,7 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
|
|||
|
||||
if( err != GRIB_SUCCESS && options->fail) exit(err);
|
||||
}
|
||||
if (options->json_output) { //JSON TODO
|
||||
if (options->json_output) {
|
||||
if (!first_handle && options->handle_count>1) {
|
||||
fprintf(stdout,",\n");
|
||||
}
|
||||
|
|
|
@ -333,7 +333,7 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
|
|||
}
|
||||
}
|
||||
|
||||
if (options->json_output) {//JSON TODO
|
||||
if (options->json_output) {
|
||||
if (!first_handle && options->handle_count>1) {
|
||||
fprintf(stdout,",\n");
|
||||
}
|
||||
|
|
|
@ -818,6 +818,19 @@ void grib_skip_check(grib_runtime_options* options,grib_handle* h)
|
|||
}
|
||||
}
|
||||
|
||||
/* TODO: Does not work for 2.7e+01 */
|
||||
static int is_value_a_number(const char* input)
|
||||
{
|
||||
const char *p = input;
|
||||
if (p == 0 || *p == 0) return 0;
|
||||
if (*p == '-') p++;
|
||||
|
||||
while (*p) {
|
||||
if( *p != '.' && !isdigit(*p)) return 0;
|
||||
p++;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
static void get_value_for_key(grib_handle* h, const char* key_name, int key_type, char* value_str, const char* format)
|
||||
{
|
||||
int ret = 0, type = key_type;
|
||||
|
@ -935,18 +948,21 @@ void grib_print_key_values(grib_runtime_options* options, grib_handle* h)
|
|||
if (!options->verbose) return;
|
||||
|
||||
if (options->json_output) {
|
||||
//fprintf(dump_file, "\"message %d\" : {\n", options->handle_count); //JSON TODO
|
||||
/* fprintf(dump_file, "\"message %d\" : {\n", options->handle_count); */
|
||||
fprintf(dump_file, "{\n");
|
||||
for (i=0;i<options->print_keys_count;i++) {
|
||||
fprintf(dump_file,"\t\"%s\": ", options->print_keys[i].name);
|
||||
get_value_for_key(h, options->print_keys[i].name, options->print_keys[i].type, value, options->format);
|
||||
fprintf(dump_file,"\"%s\"", value);
|
||||
if (is_value_a_number(value))
|
||||
fprintf(dump_file,"%s", value);
|
||||
else
|
||||
fprintf(dump_file,"\"%s\"", value);
|
||||
if (i != options->print_keys_count-1)
|
||||
fprintf(dump_file,",\n");
|
||||
else
|
||||
fprintf(dump_file,"\n");
|
||||
}
|
||||
fprintf(dump_file, "}\n"); //JSON TODO
|
||||
fprintf(dump_file, "}\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue