mirror of https://github.com/ecmwf/eccodes.git
Testing: is_in_list expression
This commit is contained in:
parent
21a76256ce
commit
ea84ba6381
|
@ -173,22 +173,23 @@ static int evaluate_long(grib_expression* g, grib_handle* h, long* result)
|
|||
|
||||
static int evaluate_double(grib_expression* g, grib_handle* h, double* result)
|
||||
{
|
||||
grib_expression_is_in_list* e = (grib_expression_is_in_list*)g;
|
||||
int err = 0;
|
||||
char mybuf[1024] = {0,};
|
||||
size_t size = 1024;
|
||||
return GRIB_NOT_IMPLEMENTED;
|
||||
// grib_expression_is_in_list* e = (grib_expression_is_in_list*)g;
|
||||
// int err = 0;
|
||||
// char mybuf[1024] = {0,};
|
||||
// size_t size = 1024;
|
||||
|
||||
grib_trie* list = load_list(h->context, g, &err);
|
||||
// grib_trie* list = load_list(h->context, g, &err);
|
||||
|
||||
if ((err = grib_get_string_internal(h, e->name, mybuf, &size)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
// if ((err = grib_get_string_internal(h, e->name, mybuf, &size)) != GRIB_SUCCESS)
|
||||
// return err;
|
||||
|
||||
if (grib_trie_get(list, mybuf))
|
||||
*result = 1;
|
||||
else
|
||||
*result = 0;
|
||||
// if (grib_trie_get(list, mybuf))
|
||||
// *result = 1;
|
||||
// else
|
||||
// *result = 0;
|
||||
|
||||
return err;
|
||||
// return err;
|
||||
}
|
||||
|
||||
static string evaluate_string(grib_expression* g, grib_handle* h, char* buf, size_t* size, int* err)
|
||||
|
|
|
@ -97,6 +97,7 @@ if( HAVE_BUILD_TOOLS )
|
|||
grib_ifsParam
|
||||
grib_packing_order
|
||||
filter_substr
|
||||
filter_is_in_list
|
||||
filter_transient_darray
|
||||
grib_uerra
|
||||
grib_ecpoint
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
#!/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.ctest.sh
|
||||
|
||||
label="filter_is_in_list_test"
|
||||
temp=temp.$label.txt
|
||||
sample=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
|
||||
|
||||
# Evaluate long
|
||||
${tools_dir}/grib_filter - $sample <<EOF
|
||||
transient a_name="#";
|
||||
if (is_in_list(a_name, "boot.def")) {
|
||||
print "Found";
|
||||
}
|
||||
EOF
|
||||
|
||||
# Evaluate string
|
||||
${tools_dir}/grib_filter - $sample <<EOF
|
||||
transient a_name="#";
|
||||
transient the_cond = (is_in_list(a_name, "boot.def"));
|
||||
if (the_cond) {
|
||||
print "Found";
|
||||
}
|
||||
EOF
|
||||
|
||||
# Illegal cases
|
||||
${tools_dir}/grib_filter - $sample 2>$temp <<EOF
|
||||
transient a_name="xyz";
|
||||
if (is_in_list(a_name, "existential nihilism")) {
|
||||
print "Found";
|
||||
}
|
||||
EOF
|
||||
grep -q "unable to find def file" $temp
|
||||
|
||||
|
||||
# Clean up
|
||||
rm -f $temp
|
Loading…
Reference in New Issue