mirror of https://github.com/ecmwf/eccodes.git
Testing: Fieldset and order_by
This commit is contained in:
parent
37a33248f8
commit
1a9b698eca
|
@ -35,14 +35,14 @@ int main(int argc, char** argv)
|
|||
int i = 0;
|
||||
codes_fieldset* set = NULL;
|
||||
codes_handle* h = NULL;
|
||||
char param[20] = {0,};
|
||||
char shortName[20] = {0,};
|
||||
size_t len = 20;
|
||||
double lats[4] = {0,};
|
||||
double lons[4] = {0,};
|
||||
double values[4] = {0,};
|
||||
double distances[4] = {0,};
|
||||
int indexes[4] = {0,};
|
||||
char* order_by = "param,step:i";
|
||||
char* order_by = "shortName,step:i";
|
||||
|
||||
size_t size = 4;
|
||||
double lat = -40, lon = 15;
|
||||
|
@ -70,9 +70,9 @@ int main(int argc, char** argv)
|
|||
while ((h = codes_fieldset_next_handle(set, &err)) != NULL) {
|
||||
CODES_CHECK(codes_get_long(h, "step", &step), 0);
|
||||
len = 20;
|
||||
CODES_CHECK(codes_get_string(h, "shortName", param, &len), 0);
|
||||
CODES_CHECK(codes_get_string(h, "shortName", shortName, &len), 0);
|
||||
|
||||
printf("Msg #%d, step=%ld, param=%s", count, step, param);
|
||||
printf("Msg #%d, step=%ld, shortName=%s", count, step, shortName);
|
||||
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);
|
||||
|
|
|
@ -20,38 +20,38 @@ ${examples_dir}/c_grib_nearest $input > $tempTxt
|
|||
|
||||
cat > $tempRef <<EOF
|
||||
|
||||
ordering by param,step:i
|
||||
ordering by shortName,step:i
|
||||
|
||||
5 fields in the fieldset
|
||||
Msg #1, step=0, param=msl
|
||||
Msg #1, step=0, shortName=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
|
||||
Msg #2, step=6, shortName=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
|
||||
Msg #3, step=12, shortName=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
|
||||
Msg #4, step=18, shortName=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
|
||||
Msg #5, step=24, shortName=msl
|
||||
Idx lat lon dist val
|
||||
58017 -40.85 15.30 97.627 101379
|
||||
58016 -40.85 14.40 107.078 101372
|
||||
|
|
|
@ -16,6 +16,7 @@ list(APPEND test_bins
|
|||
read_any
|
||||
julian
|
||||
grib_indexing
|
||||
grib_fieldset
|
||||
grib_multi_from_message
|
||||
grib_read_index
|
||||
unit_tests
|
||||
|
@ -215,6 +216,7 @@ if( HAVE_BUILD_TOOLS )
|
|||
grib_nearest_test
|
||||
pseudo_budg
|
||||
grib_gridType
|
||||
grib_fieldset
|
||||
grib_octahedral
|
||||
grib_grid_mercator
|
||||
grib_global
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* (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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "grib_api.h"
|
||||
|
||||
void usage(char* prog)
|
||||
{
|
||||
printf("Usage: %s order_by grib_file grib_file ...\n", prog);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int err = 0;
|
||||
long step;
|
||||
char** filenames;
|
||||
size_t nkeys, nfiles, i=0;
|
||||
char* keys[] = { "step:i", "date", "paramId", "levelType" };
|
||||
grib_fieldset* set = NULL;
|
||||
grib_handle* h = NULL;
|
||||
char param[20] = {0,};
|
||||
char typeOfLevel[50] = {0,};
|
||||
char date[10] = {0,};
|
||||
size_t lenDate = 10, lenParam = 20, lenLevel = 50;
|
||||
char* order_by = NULL;
|
||||
|
||||
if (argc != 3) usage(argv[0]);
|
||||
|
||||
nkeys = sizeof(keys) / sizeof(*keys);
|
||||
order_by = strdup(argv[1]);
|
||||
|
||||
nfiles = argc - 2;
|
||||
filenames = (char**)malloc(sizeof(char*) * nfiles);
|
||||
for (i = 0; i < nfiles; i++)
|
||||
filenames[i] = (char*)strdup(argv[i + 2]);
|
||||
|
||||
set = grib_fieldset_new_from_files(0, filenames, nfiles, keys, nkeys, 0, 0, &err);
|
||||
//set = grib_fieldset_new_from_files(0, filenames, nfiles, keys, nkeys, 0, order_by, &err);
|
||||
//set = grib_fieldset_new_from_files(0, filenames, nfiles, 0, 0, 0, order_by, &err);//works
|
||||
GRIB_CHECK(err, 0);
|
||||
|
||||
/* not yet implemented */
|
||||
/* err=grib_fieldset_apply_where(set,"(centre=='ecmf') && number==1 || step==6 "); */
|
||||
/* GRIB_CHECK(err,0); */
|
||||
|
||||
grib_fieldset_apply_order_by(set, order_by);
|
||||
GRIB_CHECK(err, 0);
|
||||
|
||||
printf("Ordering by %s\n", order_by);
|
||||
printf("\n%d fields in the fieldset\n", grib_fieldset_count(set));
|
||||
printf("step,date,levelType,levelType\n");
|
||||
while ((h = grib_fieldset_next_handle(set, &err)) != NULL) {
|
||||
lenParam = sizeof(param);
|
||||
lenDate = sizeof(date);
|
||||
lenLevel = sizeof(typeOfLevel);
|
||||
GRIB_CHECK(grib_get_long(h, "step", &step), 0);
|
||||
GRIB_CHECK(grib_get_string(h, "date", date, &lenDate), 0);
|
||||
GRIB_CHECK(grib_get_string(h, "paramId", param, &lenParam), 0);
|
||||
GRIB_CHECK(grib_get_string(h, "levelType", typeOfLevel, &lenLevel), 0);
|
||||
|
||||
printf("%ld %s %s %s\n", step, date, typeOfLevel, param);
|
||||
grib_handle_delete(h);
|
||||
}
|
||||
|
||||
grib_fieldset_delete(set);
|
||||
grib_handle_delete(h);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
#!/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_fieldset_test"
|
||||
temp=temp.$label.txt
|
||||
tempRef=temp.$label.ref
|
||||
input_grb=${data_dir}/high_level_api.grib2
|
||||
|
||||
$EXEC ${test_dir}/grib_fieldset 'step:i asc' $input_grb > $temp
|
||||
cat > $tempRef <<EOF
|
||||
Ordering by step:i asc
|
||||
|
||||
5 fields in the fieldset
|
||||
step,date,levelType,levelType
|
||||
0 20110225 sfc 151
|
||||
6 20110225 sfc 151
|
||||
12 20110225 sfc 151
|
||||
18 20110225 sfc 151
|
||||
24 20110225 sfc 151
|
||||
EOF
|
||||
diff $tempRef $temp
|
||||
|
||||
|
||||
$EXEC ${test_dir}/grib_fieldset 'step:i desc' $input_grb > $temp
|
||||
cat > $tempRef <<EOF
|
||||
Ordering by step:i desc
|
||||
|
||||
5 fields in the fieldset
|
||||
step,date,levelType,levelType
|
||||
24 20110225 sfc 151
|
||||
18 20110225 sfc 151
|
||||
12 20110225 sfc 151
|
||||
6 20110225 sfc 151
|
||||
0 20110225 sfc 151
|
||||
EOF
|
||||
diff $tempRef $temp
|
||||
|
||||
# Clean up
|
||||
rm -f $temp $tempRef
|
Loading…
Reference in New Issue