Testing: C example for fieldset with numeric sorting

This commit is contained in:
Shahram Najm 2022-02-23 18:36:45 +00:00
parent 1fb1394a55
commit 23e5cba453
3 changed files with 69 additions and 3 deletions

View File

@ -82,6 +82,7 @@ if( HAVE_BUILD_TOOLS )
grib_set_bitmap
grib_list
grib_get_data
grib_nearest
grib_nearest_multiple
grib_multi
grib_set_missing

View File

@ -42,7 +42,7 @@ int main(int argc, char** argv)
double values[4] = {0,};
double distances[4] = {0,};
int indexes[4] = {0,};
char* order_by = "param,step";
char* order_by = "param,step:i";
size_t size = 4;
double lat = -40, lon = 15;
@ -63,7 +63,6 @@ int main(int argc, char** argv)
printf("\nordering by %s\n", order_by);
printf("\n%d fields in the fieldset\n", codes_fieldset_count(set));
printf("n,step,param\n");
mode = CODES_NEAREST_SAME_GRID | CODES_NEAREST_SAME_POINT;
count = 1;
@ -73,7 +72,7 @@ int main(int argc, char** argv)
len = 20;
CODES_CHECK(codes_get_string(h, "shortName", param, &len), 0);
printf("%d %ld %s ", count, step, param);
printf("Msg #%d, step=%ld, param=%s", count, step, param);
if (!nearest) nearest = codes_grib_nearest_new(h, &err);
CODES_CHECK(err, 0);
CODES_CHECK(codes_grib_nearest_find(nearest, h, lat, lon, mode, lats, lons, values, distances, indexes, &size), 0);

66
examples/C/grib_nearest.sh Executable file
View File

@ -0,0 +1,66 @@
#!/bin/sh
# (C) Copyright 2005- 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
set -u
label="grib_nearest_c"
tempTxt=temp.$label.txt
tempRef=temp.$label.ref
input=${data_dir}/high_level_api.grib2
${examples_dir}/c_grib_nearest $input > $tempTxt
cat > $tempRef <<EOF
ordering by param,step:i
5 fields in the fieldset
Msg #1, step=0, param=msl
Idx lat lon dist val
58017 -40.85 15.30 97.627 101524
58016 -40.85 14.40 107.078 101570
57617 -39.95 15.30 26.1625 101655
57616 -39.95 14.40 51.4303 101669
Msg #2, step=6, param=msl
Idx lat lon dist val
58017 -40.85 15.30 97.627 101547
58016 -40.85 14.40 107.078 101605
57617 -39.95 15.30 26.1625 101589
57616 -39.95 14.40 51.4303 101641
Msg #3, step=12, param=msl
Idx lat lon dist val
58017 -40.85 15.30 97.627 101606
58016 -40.85 14.40 107.078 101623
57617 -39.95 15.30 26.1625 101652
57616 -39.95 14.40 51.4303 101678
Msg #4, step=18, param=msl
Idx lat lon dist val
58017 -40.85 15.30 97.627 101507
58016 -40.85 14.40 107.078 101486
57617 -39.95 15.30 26.1625 101573
57616 -39.95 14.40 51.4303 101571
Msg #5, step=24, param=msl
Idx lat lon dist val
58017 -40.85 15.30 97.627 101379
58016 -40.85 14.40 107.078 101372
57617 -39.95 15.30 26.1625 101494
57616 -39.95 14.40 51.4303 101471
EOF
diff $tempRef $tempTxt
rm -f $tempTxt $tempRef