mirror of https://github.com/ecmwf/eccodes.git
Merge branch 'convert-to-cpp' of github.com:ecmwf/eccodes into convert-to-cpp
This commit is contained in:
commit
f6a041aba2
|
@ -127,47 +127,8 @@ static void dump(grib_action* act, FILE* f, int lvl)
|
|||
grib_context_print(act->context, f, "%s[%d] %s \n", act->op, a->len, act->name);
|
||||
}
|
||||
|
||||
// #define F(x) if (flg & x) { fprintf(f, "%s=>1,", #x); flg &= !x; }
|
||||
// static int count = 0;
|
||||
// static void xref(grib_action* act, FILE* f, const char* path)
|
||||
// {
|
||||
// grib_action_gen* a = (grib_action_gen*)act;
|
||||
// unsigned long flg = act->flags;
|
||||
// int position = a->len > 0 ? count++ : -1;
|
||||
|
||||
// fprintf(f, "bless({path=>'%s',size => %ld, name=> '%s', position=> %d, ", path, (long)a->len, act->name, position);
|
||||
|
||||
// fprintf(f, " params=> [");
|
||||
// grib_arguments_print(act->context, a->params, NULL);
|
||||
// fprintf(f, "], flags=> {");
|
||||
|
||||
// F(GRIB_ACCESSOR_FLAG_READ_ONLY);
|
||||
// F(GRIB_ACCESSOR_FLAG_DUMP);
|
||||
// F(GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC);
|
||||
// F(GRIB_ACCESSOR_FLAG_CAN_BE_MISSING);
|
||||
// F(GRIB_ACCESSOR_FLAG_HIDDEN);
|
||||
// F(GRIB_ACCESSOR_FLAG_CONSTRAINT);
|
||||
// F(GRIB_ACCESSOR_FLAG_NO_COPY);
|
||||
// F(GRIB_ACCESSOR_FLAG_COPY_OK);
|
||||
// F(GRIB_ACCESSOR_FLAG_FUNCTION);
|
||||
// F(GRIB_ACCESSOR_FLAG_DATA);
|
||||
// F(GRIB_ACCESSOR_FLAG_NO_FAIL);
|
||||
// F(GRIB_ACCESSOR_FLAG_TRANSIENT);
|
||||
// F(GRIB_ACCESSOR_FLAG_STRING_TYPE);
|
||||
// F(GRIB_ACCESSOR_FLAG_LONG_TYPE);
|
||||
// F(GRIB_ACCESSOR_FLAG_DOUBLE_TYPE);
|
||||
|
||||
// /* make sure all flags are processed */
|
||||
// if (flg) {
|
||||
// printf("FLG = %ld\n", (long)flg);
|
||||
// }
|
||||
// Assert(flg == 0);
|
||||
|
||||
// fprintf(f, "}, defaults=> [");
|
||||
// grib_arguments_print(act->context, act->default_value, NULL);
|
||||
|
||||
// fprintf(f, "]}, 'xref::%s'),\n", act->op);
|
||||
// }
|
||||
// For xref implementation see
|
||||
// src/deprecated/action_class_gen.cc
|
||||
|
||||
static void xref(grib_action* act, FILE* f, const char* path)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
// #define F(x) if (flg & x) { fprintf(f, "%s=>1,", #x); flg &= !x; }
|
||||
// static int count = 0;
|
||||
// static void xref(grib_action* act, FILE* f, const char* path)
|
||||
// {
|
||||
// grib_action_gen* a = (grib_action_gen*)act;
|
||||
// unsigned long flg = act->flags;
|
||||
// int position = a->len > 0 ? count++ : -1;
|
||||
|
||||
// fprintf(f, "bless({path=>'%s',size => %ld, name=> '%s', position=> %d, ", path, (long)a->len, act->name, position);
|
||||
|
||||
// fprintf(f, " params=> [");
|
||||
// grib_arguments_print(act->context, a->params, NULL);
|
||||
// fprintf(f, "], flags=> {");
|
||||
|
||||
// F(GRIB_ACCESSOR_FLAG_READ_ONLY);
|
||||
// F(GRIB_ACCESSOR_FLAG_DUMP);
|
||||
// F(GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC);
|
||||
// F(GRIB_ACCESSOR_FLAG_CAN_BE_MISSING);
|
||||
// F(GRIB_ACCESSOR_FLAG_HIDDEN);
|
||||
// F(GRIB_ACCESSOR_FLAG_CONSTRAINT);
|
||||
// F(GRIB_ACCESSOR_FLAG_NO_COPY);
|
||||
// F(GRIB_ACCESSOR_FLAG_COPY_OK);
|
||||
// F(GRIB_ACCESSOR_FLAG_FUNCTION);
|
||||
// F(GRIB_ACCESSOR_FLAG_DATA);
|
||||
// F(GRIB_ACCESSOR_FLAG_NO_FAIL);
|
||||
// F(GRIB_ACCESSOR_FLAG_TRANSIENT);
|
||||
// F(GRIB_ACCESSOR_FLAG_STRING_TYPE);
|
||||
// F(GRIB_ACCESSOR_FLAG_LONG_TYPE);
|
||||
// F(GRIB_ACCESSOR_FLAG_DOUBLE_TYPE);
|
||||
|
||||
// /* make sure all flags are processed */
|
||||
// if (flg) {
|
||||
// printf("FLG = %ld\n", (long)flg);
|
||||
// }
|
||||
// Assert(flg == 0);
|
||||
|
||||
// fprintf(f, "}, defaults=> [");
|
||||
// grib_arguments_print(act->context, act->default_value, NULL);
|
||||
|
||||
// fprintf(f, "]}, 'xref::%s'),\n", act->op);
|
||||
// }
|
||||
|
||||
static void xref(grib_action* act, FILE* f, const char* path)
|
||||
{
|
||||
Assert(!"xref is disabled");
|
||||
}
|
|
@ -320,12 +320,13 @@ static int unpack(grib_accessor* a, T* v, size_t* len)
|
|||
{
|
||||
static_assert(std::is_floating_point<T>::value, "Requires floating point numbers");
|
||||
int type = GRIB_TYPE_UNDEFINED;
|
||||
const char* Tname = type_to_string<T>(*v);
|
||||
if (a->cclass->unpack_long && a->cclass->unpack_long != &unpack_long) {
|
||||
long val = 0;
|
||||
size_t l = 1;
|
||||
grib_unpack_long(a, &val, &l);
|
||||
*v = val;
|
||||
grib_context_log(a->context, GRIB_LOG_DEBUG, "Casting long %s to %s", a->name, type_to_string<T>(*v));
|
||||
grib_context_log(a->context, GRIB_LOG_DEBUG, "Casting long %s to %s", a->name, Tname);
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -337,12 +338,12 @@ static int unpack(grib_accessor* a, T* v, size_t* len)
|
|||
|
||||
*v = strtod(val, &last);
|
||||
if (*last == 0) { /* conversion of string to double worked */
|
||||
grib_context_log(a->context, GRIB_LOG_DEBUG, "Casting string %s to long", a->name);
|
||||
grib_context_log(a->context, GRIB_LOG_DEBUG, "Casting string %s to %s", a->name, Tname);
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "Cannot unpack as %s", a->name);
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "Cannot unpack %s as %s", a->name, Tname);
|
||||
if (grib_get_native_type(grib_handle_of_accessor(a), a->name, &type) == GRIB_SUCCESS) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "Hint: Try unpacking as %s", grib_get_type_name(type));
|
||||
}
|
||||
|
|
|
@ -80,5 +80,23 @@ ${tools_dir}/grib_set -s gridType=polar_stereographic $grib2_sample $tempGrib
|
|||
${tools_dir}/grib_get -p projString $tempGrib > $tempText
|
||||
grep -q "proj=stere" $tempText
|
||||
|
||||
# Test invalid decode
|
||||
set +e
|
||||
${tools_dir}/grib_get -p projString:i $grib2_sample > $tempText 2>&1
|
||||
status=$?
|
||||
set -e
|
||||
[ $status -ne 0 ]
|
||||
grep -q "ERROR.*Cannot unpack projTargetString as long" $tempText
|
||||
grep -q "Hint: Try unpacking as string" $tempText
|
||||
|
||||
set +e
|
||||
${tools_dir}/grib_get -p projString:d $grib2_sample > $tempText 2>&1
|
||||
status=$?
|
||||
set -e
|
||||
[ $status -ne 0 ]
|
||||
grep -q "ERROR.*Cannot unpack projTargetString as double" $tempText
|
||||
grep -q "Hint: Try unpacking as string" $tempText
|
||||
|
||||
|
||||
# Clean up
|
||||
rm -f $tempGrib $tempText
|
||||
|
|
|
@ -128,6 +128,18 @@ grib_check_key_equals $temp stepType avg
|
|||
${tools_dir}/grib_set -s stepType=avg $grib2_sample $temp
|
||||
grib_check_key_equals $temp typeOfTimeIncrement 3
|
||||
|
||||
# Decode/Encode stepRange as an int and double
|
||||
${tools_dir}/grib_set -s stepType=accum,stepRange=23-28 $grib2_sample $temp
|
||||
grib_check_key_equals $temp "stepRange:s" "23-28"
|
||||
grib_check_key_equals $temp "stepRange:i" "28"
|
||||
grib_check_key_equals $temp "stepRange:d" "28"
|
||||
|
||||
${tools_dir}/grib_set -s stepRange:i=24 $grib2_sample $temp
|
||||
grib_check_key_equals $temp "stepRange,startStep,endStep" "24 24 24"
|
||||
# Should this be an error? currently this gets cast from double to int
|
||||
${tools_dir}/grib_set -s stepRange:d=14.56 $grib2_sample $temp
|
||||
grib_check_key_equals $temp "stepRange,startStep,endStep" "14 14 14"
|
||||
|
||||
|
||||
# Clean up
|
||||
rm -f $temp
|
||||
|
|
Loading…
Reference in New Issue