2023-10-10 08:12:53 +00:00
|
|
|
/*
|
|
|
|
* (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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "grib_scaling.h"
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <type_traits>
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
/**
|
|
|
|
.. _init_ieee_table:
|
|
|
|
|
|
|
|
Init IBM Floats Table
|
2023-10-12 10:38:40 +00:00
|
|
|
=====================
|
2023-10-10 08:12:53 +00:00
|
|
|
|
|
|
|
Initializes the ibm_table with IBM Float values. Nearest smaller values (e.g., reference values for grid_simple) are taken from this table.
|
|
|
|
|
|
|
|
Details
|
|
|
|
-------
|
|
|
|
|
|
|
|
The table layout is as follows:
|
|
|
|
|
2023-10-12 10:38:40 +00:00
|
|
|
+-------+----------------+------------------------+
|
2023-10-10 08:12:53 +00:00
|
|
|
| idx (i) | multiplier (e) | value (v = mmin * e) |
|
2023-10-12 10:38:40 +00:00
|
|
|
+-------+----------------+------------------------+
|
2024-12-18 16:52:24 +00:00
|
|
|
| 0 | 16^(-70) | 0x100000 * 16^(-70) |
|
|
|
|
| 1 | 16^(-69) | 0x100000 * 16^(-69) |
|
2023-10-12 10:38:40 +00:00
|
|
|
| ... | ... | ... |
|
2024-12-18 16:52:24 +00:00
|
|
|
| 126 | 16^56 | 0x100000 * 16^56 |
|
|
|
|
| 127 | 16^57 | 0x100000 * 16^57 |
|
2023-10-12 10:38:40 +00:00
|
|
|
+-------+----------------+------------------------+
|
2023-10-10 08:12:53 +00:00
|
|
|
|
|
|
|
The vmin and vmax boundaries are defined as:
|
|
|
|
|
2024-12-18 16:52:24 +00:00
|
|
|
- vmin = 0x100000 * 16^(-70)
|
|
|
|
- vmax = 0xffffff * 16^57
|
2023-10-10 08:12:53 +00:00
|
|
|
*/
|
|
|
|
|
2024-12-18 16:52:24 +00:00
|
|
|
struct IbmTable
|
|
|
|
{
|
2023-10-10 08:12:53 +00:00
|
|
|
private:
|
2024-12-18 16:52:24 +00:00
|
|
|
using ValueType = double;
|
|
|
|
static constexpr int TABLESIZE = 128;
|
2023-10-10 08:12:53 +00:00
|
|
|
static constexpr uint32_t mantissa_min = 0x100000;
|
|
|
|
static constexpr uint32_t mantissa_max = 0xffffff;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static constexpr std::array<ValueType, TABLESIZE> e = []() {
|
|
|
|
std::array<ValueType, TABLESIZE> multiplier{};
|
2023-10-12 12:42:17 +00:00
|
|
|
multiplier[0] = 0;
|
|
|
|
for (int i = 0; i < TABLESIZE; ++i) {
|
2023-10-10 08:12:53 +00:00
|
|
|
multiplier[i] = codes_power<ValueType>(i - 70, 16);
|
|
|
|
}
|
|
|
|
return multiplier;
|
|
|
|
}();
|
|
|
|
static constexpr std::array<ValueType, TABLESIZE> v = []() {
|
|
|
|
std::array<ValueType, TABLESIZE> values{};
|
2023-10-12 12:42:17 +00:00
|
|
|
values[0] = 0;
|
|
|
|
for (int i = 0; i < TABLESIZE; ++i) {
|
2023-10-10 08:12:53 +00:00
|
|
|
values[i] = e[i] * mantissa_min;
|
|
|
|
}
|
|
|
|
return values;
|
|
|
|
}();
|
|
|
|
static constexpr ValueType vmin = e[0] * mantissa_min;
|
|
|
|
static constexpr ValueType vmax = e[127] * mantissa_max;
|
|
|
|
};
|