Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
f2ae370
ECC-2393: Add a test
joobog Nov 26, 2026
fbc1eab
ECC-2393: Fix spectral complex packing of fields with a very steep sp…
joobog Nov 26, 2026
24cc46e
spectral_complex: new library for GRIB spectral complex packing
joobog Nov 26, 2026
6f195ea
spectral_complex: use it in ecCodes with ECCODES_USE_SC=1
joobog Nov 26, 2026
8332ac2
spectral_complex: fuzzers, benchmarks, ecCodes legacy test
joobog Nov 26, 2026
2ff587f
spectral_complex: fixes from the attack tests
joobog Nov 26, 2026
e3f117a
spectral_complex: laplacian operator with the smallest expected error…
joobog Dec 2, 2026
5ead6fb
spectral_complex: test for the optimal operator of fields too small t…
joobog Dec 2, 2026
20e85b4
spectral_complex: optimal operator 0 for fields too small to be coded
joobog Dec 2, 2026
0532108
spectral_complex: the optimal operator is guaranteed for fields with …
joobog Dec 2, 2026
10d2bef
spectral_complex: test for arguments of sc::parameters that cannot be…
joobog Dec 2, 2026
08de659
spectral_complex: sc::parameters rejects decimal scale factors and op…
joobog Dec 2, 2026
b4fe07f
spectral_complex: document how to store the optimal operator
joobog Dec 2, 2026
5f1a848
spectral_complex: test for operators that overflow when packing or un…
joobog Dec 2, 2026
3230992
spectral_complex: reject operators that overflow when packing or unpa…
joobog Dec 2, 2026
26bc81e
spectral_complex: document the limits of the optimal operator
joobog Dec 2, 2026
4477266
spectral_complex: test for coefficients at the largest double
joobog Dec 2, 2026
5bf910b
spectral_complex: margin for coefficients near the largest double
joobog Dec 2, 2026
b52b848
spectral_complex: test for the order of the decimal scaling
joobog Dec 2, 2026
fd27dbc
spectral_complex: check the codes in the order of sc::pack and the fl…
joobog Dec 2, 2026
01883d6
spectral_complex: random test of the optimal operator for gaps found …
joobog Dec 2, 2026
c1063a3
spectral_complex: document re-packing of decoded values
joobog Dec 2, 2026
b121ff3
spectral_complex: test for the optimal operator near the limits of th…
joobog Dec 2, 2026
757cfae
spectral_complex: skip steps that cannot be unpacked, bound the error…
joobog Dec 2, 2026
31ec5f5
spectral_complex: test for a narrow range of operators that can be un…
joobog Dec 2, 2026
72ab48a
spectral_complex: scan for codable operators before giving up
joobog Dec 2, 2026
fc7a0d4
spectral_complex: random test skips fields that cannot be coded or ar…
joobog Dec 2, 2026
28cf38b
spectral_complex: test for rows of zeros, found by mutation testing
joobog Dec 2, 2026
a85f9af
spectral_complex: format test
joobog Dec 2, 2026
845ae26
ECC-2393: ECCODES_SC_OPERATOR=optimal selects the optimal laplacian o…
joobog Dec 2, 2026
015ee28
spectral_complex: test the optimal operator with bestPrecision
joobog Dec 2, 2026
263d94a
spectral_complex: step search for the optimal operator also with best…
joobog Dec 2, 2026
5084336
ECC-782: an invalid section number in multi-field mode is not an erro…
joobog Dec 2, 2026
e16f1cf
spectral_complex: test the exit status for 64 bits per value in ecCodes
joobog Dec 2, 2026
6734f2c
spectral_complex: GRIB_OUT_OF_RANGE for more than 63 bits per value i…
joobog Dec 2, 2026
9412739
Tests of the legacy laplacian operator select it explicitly
joobog Dec 2, 2026
85d2075
spectral_complex: one scaling for sc::parameters and the optimal oper…
joobog Dec 2, 2026
ccc0578
spectral_complex: separate the optimal operator from the legacy algor…
joobog Dec 2, 2026
e499e04
spectral_complex: test for the operator of zero-padded fields (ECC-2381)
joobog Dec 4, 2026
d145623
spectral_complex: operator 1 for fewer than two packed rows above 1e-…
joobog Dec 4, 2026
58f1206
Clang-format (pre-commit)
joobog Dec 4, 2026
129bae2
spectral_complex: restore the packing speed, checks out of the hot loop
joobog Dec 4, 2026
64bf73b
Legacy comparison test of spectral complex packing selects the legacy…
joobog Dec 4, 2026
1423580
spectral_complex: rewrite the documentation, describe the laplacian o…
joobog Dec 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ ecbuild_add_option( FEATURE AEC
# with AEC libaec is the default and ECCODES_USE_SPAEC=1 selects SpAec at runtime.
# Simple packing: the legacy code and the simple_packing library (projects/simple_packing) are
# both built. The legacy code is the default; ECCODES_USE_SP=1 selects the library.
# Spectral complex packing: the legacy code and the spectral_complex library
# (projects/spectral_complex) are both built. The legacy code is the default; ECCODES_USE_SC=1
# selects the library. ECCODES_SC_OPERATOR=optimal selects the library with the laplacian operator
# of the smallest expected error (ECC-2393) instead of the fit of legacy ecCodes.

ecbuild_find_python( VERSION 3.6 NO_LIBS )
# find_package( NumPy )
Expand Down Expand Up @@ -490,6 +494,9 @@ add_subdirectory( projects/spaec )
set( SIMPLE_PACKING_BUILD_TESTS ${ENABLE_TESTS} )
set( SIMPLE_PACKING_INSTALL OFF )
add_subdirectory( projects/simple_packing )
set( SPECTRAL_COMPLEX_BUILD_TESTS ${ENABLE_TESTS} )
set( SPECTRAL_COMPLEX_INSTALL OFF )
add_subdirectory( projects/spectral_complex )
add_subdirectory( src )
if( HAVE_BUILD_TOOLS )
add_subdirectory( tools )
Expand Down
108 changes: 108 additions & 0 deletions projects/spectral_complex/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
---
Language: Cpp
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignConsecutiveMacros: true
AlignEscapedNewlines: Left
AlignOperands: AlignAfterOperator
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: true
AfterControlStatement: false
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: false
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: AfterColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 0
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeCategories:
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: true
IndentPPDirectives: BeforeHash
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 2
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: false
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
ReflowComments: true
SortIncludes: false
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
TabWidth: 4
UseTab: Never
...
74 changes: 74 additions & 0 deletions projects/spectral_complex/.clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
# bugprone-assignment-in-if-condition stays off: -Wparentheses already catches
# `if (a = b)`, and `if ((err = f()))` is the idiom here.
# The trailing -<check> entries are findings not yet fixed; each fix drops its entry.
Checks: >
-*,
bugprone-*,
clang-analyzer-*,
performance-*,
cert-err33-c,
concurrency-mt-unsafe,
misc-redundant-expression,
readability-misleading-indentation,
-bugprone-assignment-in-if-condition,
-bugprone-argument-comment,
-bugprone-branch-clone,
-bugprone-easily-swappable-parameters,
-bugprone-empty-catch,
-bugprone-forward-declaration-namespace,
-bugprone-implicit-widening-of-multiplication-result,
-bugprone-inc-dec-in-conditions,
-bugprone-incorrect-roundings,
-bugprone-integer-division,
-bugprone-macro-parentheses,
-bugprone-misplaced-widening-cast,
-bugprone-multi-level-implicit-pointer-conversion,
-bugprone-narrowing-conversions,
-bugprone-not-null-terminated-result,
-bugprone-reserved-identifier,
-bugprone-signed-char-misuse,
-bugprone-suspicious-include,
-bugprone-suspicious-string-compare,
-bugprone-switch-missing-default-case,
-bugprone-unsafe-functions,
-clang-analyzer-core.BitwiseShift,
-clang-analyzer-core.NonNullParamChecker,
-clang-analyzer-core.NullDereference,
-clang-analyzer-core.UndefinedBinaryOperatorResult,
-clang-analyzer-deadcode.DeadStores,
-clang-analyzer-optin.performance.Padding,
-clang-analyzer-security.insecureAPI.strcpy,
-clang-analyzer-unix.Malloc,
-concurrency-mt-unsafe,
-performance-enum-size,
-performance-inefficient-vector-operation,
-performance-unnecessary-value-param
# The code is not yet clean under these checks (mostly bugprone-signed-bitwise): they are reported as
# warnings, not errors. Set WarningsAsErrors: '*' once it is.
WarningsAsErrors: ''
CheckOptions:
# The default list without the printf family and fclose: a failed write to a
# stream or buffer is rarely something the caller can handle, and most files
# here are read-only. Files that are written check their fclose by hand.
cert-err33-c.CheckedFunctions: >-
::asctime_s; ::at_quick_exit; ::atexit; ::bsearch; ::bsearch_s; ::btowc; ::c16rtomb; ::c32rtomb;
::calloc; ::clock; ::cnd_broadcast; ::cnd_init; ::cnd_signal; ::cnd_timedwait; ::cnd_wait;
::ctime_s; ::fflush; ::fgetc; ::fgetpos; ::fgets; ::fgetwc; ::fopen; ::fopen_s;
::fread; ::freopen; ::freopen_s; ::fscanf; ::fscanf_s; ::fseek; ::fsetpos; ::ftell; ::fwrite;
::fwscanf; ::fwscanf_s; ::getc; ::getchar; ::getenv; ::getenv_s; ::gets_s; ::getwc; ::getwchar;
::gmtime; ::gmtime_s; ::localtime; ::localtime_s; ::malloc; ::mbrtoc16; ::mbrtoc32; ::mbsrtowcs;
::mbsrtowcs_s; ::mbstowcs; ::mbstowcs_s; ::memchr; ::mktime; ::mtx_init; ::mtx_lock;
::mtx_timedlock; ::mtx_trylock; ::mtx_unlock; ::raise; ::realloc; ::remove; ::rename; ::scanf;
::scanf_s; ::setlocale; ::setvbuf; ::signal; ::sscanf; ::sscanf_s; ::strchr; ::strerror_s;
::strftime; ::strpbrk; ::strrchr; ::strstr; ::strtod; ::strtof; ::strtoimax; ::strtok;
::strtok_s; ::strtol; ::strtold; ::strtoll; ::strtoul; ::strtoull; ::strtoumax; ::strxfrm;
::swscanf; ::swscanf_s; ::thrd_create; ::thrd_detach; ::thrd_join; ::thrd_sleep; ::time;
::timespec_get; ::tmpfile; ::tmpfile_s; ::tmpnam; ::tmpnam_s; ::tss_create; ::tss_get;
::tss_set; ::ungetc; ::ungetwc; ::vfscanf; ::vfscanf_s; ::vfwscanf; ::vfwscanf_s; ::vscanf;
::vscanf_s; ::vsscanf; ::vsscanf_s; ::vswscanf; ::vswscanf_s; ::vwscanf; ::vwscanf_s; ::wcrtomb;
::wcschr; ::wcsftime; ::wcspbrk; ::wcsrchr; ::wcsrtombs; ::wcsrtombs_s; ::wcsstr; ::wcstod;
::wcstof; ::wcstoimax; ::wcstok; ::wcstok_s; ::wcstol; ::wcstold; ::wcstoll; ::wcstombs;
::wcstombs_s; ::wcstoul; ::wcstoull; ::wcstoumax; ::wcsxfrm; ::wctob; ::wctrans; ::wctype;
::wmemchr; ::wscanf; ::wscanf_s
...
6 changes: 6 additions & 0 deletions projects/spectral_complex/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Build directories and files generated by tools
build/
build-*/
compile_commands.json
.cache/
.clangd
60 changes: 60 additions & 0 deletions projects/spectral_complex/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!--
SPDX-FileCopyrightText: 2026 European Centre for Medium-Range Weather Forecasts (ECMWF)
SPDX-License-Identifier: Apache-2.0
-->

# Changelog

All notable changes to spectral_complex. The version is defined in
[`include/spectral_complex/version.h`](include/spectral_complex/version.h). The interface may still change before version 1.0.0.

## 0.0.1 (unreleased)

First version.

### Packing and unpacking

- GRIB spectral complex packing: `sc::parameters`, `sc::pack`, `sc::unpack`, `sc::Layout`,
`sc::Parameters`, `sc::Method`.
- Unpacked coefficients as IEEE32, IEEE64 or IBM32 floats; packed coefficients with 1 to 63 bits per
value and an IEEE (GRIB2) or IBM (GRIB1) reference value; unpacking to `float` and `double`.
- Packed data byte-identical to legacy ecCodes, including the GRIBEX sh bug, the underflow of the
binary scale factor and JS = J. Decoded values bit-identical.
- Errors are exceptions where legacy ecCodes fails an assertion or codes garbage. `sc::parameters`
rejects:
- NaN and infinite coefficients (detected from their bit pattern, also with `-ffast-math` in the
including code);
- scaled values beyond the range of the reference value or of the binary scale factor (ECC-2393);
- a decimal scale factor beyond 16 bits, or with a 10^D that is not a normal number;
- an operator whose factors `(n(n+1))^P` or their inverses are not normal numbers;
- an operator with which packing or unpacking would overflow or lose precision.

### The laplacian operator

- `sc::laplacianOperator`: the fit of legacy ecCodes, bit-identical, including GRIB-172 (one packed
row), ECC-2381 (fewer than two rows above 1e-15, e.g. zero-padded fields) and ECC-2393 (very steep
spectra).
- `sc::optimalLaplacianOperator` (ECC-2393, header
[`spectral_complex/optimal_operator.h`](include/spectral_complex/optimal_operator.h)): the
operator with the smallest expected error of the packed coefficients, among the operators that the
message can store (`sc::OperatorCoding`) and with which the field can be packed and unpacked. It
is separate from the rest of the library. Described in
[docs/laplacian_operator.md](docs/laplacian_operator.md).

### Build and tests

- Floating-point compiler options `ON` by default (`SPECTRAL_COMPLEX_FP_CONTRACT_OFF`,
`SPECTRAL_COMPLEX_NO_FAST_MATH`, `SPECTRAL_COMPLEX_NO_TRAPPING_MATH`). Configure checks the
floating-point behaviour of the build flags and warns if it is not exact.
- Tests against a frozen copy of the legacy code, compiled with fixed floating-point options; the
optimal operator against brute force over all GRIB1 operators; regression tests.
- Benchmark `benchmarks/sc_bench` (`SPECTRAL_COMPLEX_BUILD_BENCHMARKS`), libFuzzer fuzzers
(`SPECTRAL_COMPLEX_BUILD_FUZZERS`), install test.
- Packing and unpacking tested on Linux (GCC, Clang, Intel icx; x86-64, AArch64, s390x) and on
Windows with MinGW-w64; the optimal operator on Linux x86-64 with GCC and Clang.

### ecCodes

- `ECCODES_USE_SC=1` selects the library (`DataComplexPackingNew.cc`); the messages are
byte-identical to the legacy code, which stays the default.
- `ECCODES_SC_OPERATOR=optimal` selects the library with the optimal laplacian operator.
Loading
Loading