|
| 1 | +/* |
| 2 | + * (C) Copyright 2005- ECMWF. |
| 3 | + * |
| 4 | + * This software is licensed under the terms of the Apache Licence Version 2.0 |
| 5 | + * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. |
| 6 | + * |
| 7 | + * In applying this licence, ECMWF does not waive the privileges and immunities granted to it by |
| 8 | + * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. |
| 9 | + */ |
| 10 | + |
| 11 | +#include "G2Probability.h" |
| 12 | + |
| 13 | +eccodes::accessor::G2Probability _grib_accessor_g2_probability; |
| 14 | +eccodes::Accessor* grib_accessor_g2_probability = &_grib_accessor_g2_probability; |
| 15 | + |
| 16 | +namespace eccodes::accessor |
| 17 | +{ |
| 18 | + |
| 19 | +void G2Probability::init(const long l, grib_arguments* c) |
| 20 | +{ |
| 21 | + Unsigned::init(l, c); |
| 22 | + grib_handle* hand = get_enclosing_handle(); |
| 23 | + int n = 0; |
| 24 | + |
| 25 | + productDefinitionTemplateNumber_ = c->get_name(hand, n++); |
| 26 | + stepType_ = c->get_name(hand, n++); |
| 27 | +} |
| 28 | + |
| 29 | +int G2Probability::unpack_long(long* val, size_t* len) |
| 30 | +{ |
| 31 | + long productDefinitionTemplateNumber = 0; |
| 32 | + grib_get_long(get_enclosing_handle(), productDefinitionTemplateNumber_, &productDefinitionTemplateNumber); |
| 33 | + *val = (productDefinitionTemplateNumber == 5 || productDefinitionTemplateNumber == 9); |
| 34 | + |
| 35 | + return GRIB_SUCCESS; |
| 36 | +} |
| 37 | + |
| 38 | +int G2Probability::pack_long(const long* val, size_t* len) |
| 39 | +{ |
| 40 | + grib_handle* hand = get_enclosing_handle(); |
| 41 | + long productDefinitionTemplateNumber = -1; |
| 42 | + long productDefinitionTemplateNumberNew = -1; |
| 43 | + char stepType[15] = {0,}; |
| 44 | + size_t slen = 15; |
| 45 | + int isInstant = 0; |
| 46 | + int ret = 0; |
| 47 | + |
| 48 | + if (grib_get_long(hand, productDefinitionTemplateNumber_, &productDefinitionTemplateNumber) != GRIB_SUCCESS) |
| 49 | + return GRIB_SUCCESS; |
| 50 | + |
| 51 | + ret = grib_get_string(hand, stepType_, stepType, &slen); |
| 52 | + ECCODES_ASSERT(ret == GRIB_SUCCESS); |
| 53 | + |
| 54 | + // long eps = grib_is_defined(hand, "perturbationNumber"); |
| 55 | + |
| 56 | + if (!strcmp(stepType, "instant")) |
| 57 | + isInstant = 1; |
| 58 | + |
| 59 | + if (isInstant) { |
| 60 | + productDefinitionTemplateNumberNew = 5; |
| 61 | + } |
| 62 | + else { |
| 63 | + productDefinitionTemplateNumberNew = 9; |
| 64 | + } |
| 65 | + |
| 66 | + if (productDefinitionTemplateNumber != productDefinitionTemplateNumberNew) { |
| 67 | + grib_set_long(hand, productDefinitionTemplateNumber_, productDefinitionTemplateNumberNew); |
| 68 | + } |
| 69 | + |
| 70 | + return 0; |
| 71 | +} |
| 72 | + |
| 73 | +int G2Probability::value_count(long* count) |
| 74 | +{ |
| 75 | + *count = 1; |
| 76 | + return 0; |
| 77 | +} |
| 78 | + |
| 79 | +} // namespace eccodes::accessor |
0 commit comments