Merge branch 'develop' into feature/destine_tile_template

This commit is contained in:
Shahram Najm 2023-03-01 11:00:54 +00:00
commit 397e319ffe
57 changed files with 1661 additions and 1435 deletions

View File

@ -4,6 +4,7 @@ AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: false
AlignConsecutiveMacros: true
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
@ -66,6 +67,7 @@ IncludeCategories:
Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: true
IndentPPDirectives: BeforeHash
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave

24
.github/workflows/sync.yml vendored Normal file
View File

@ -0,0 +1,24 @@
name: sync
# Controls when the workflow will run
on:
# Trigger the workflow on all pushes
push:
branches:
- "**"
tags:
- "**"
# Trigger the workflow when a branch or tag is deleted
delete: ~
jobs:
# Calls a reusable CI workflow to sync the current with a remote repository.
# It will correctly handle addition of any new and removal of existing Git objects.
sync:
name: sync
uses: ecmwf-actions/reusable-workflows/.github/workflows/sync.yml@v2
secrets:
target_repository: eccodes/eccodes
target_username: ClonedDuck
target_token: ${{ secrets.BITBUCKET_PAT }}

View File

@ -12,13 +12,18 @@ file(READ "bufr_ref_files.txt" bufr_refs_to_download)
string(REGEX REPLACE "\n" ";" bufr_refs_to_download "${bufr_refs_to_download}")
# Exceptional case: download bufr files which have to be treated specially
list(APPEND bufr_refs_to_download "vos308014_v3_26.bufr") # See test ecc-197
list(APPEND bufr_files_to_download "vos308014_v3_26.bufr") # See test ecc-197
if( ENABLE_EXTRA_TESTS )
ecbuild_get_test_multidata(
TARGET eccodes_download_bufrs
NOCHECK
NAMES ${bufr_files_to_download} ${bufr_refs_to_download}
TARGET eccodes_download_bufrs
NOCHECK
NAMES ${bufr_files_to_download}
)
ecbuild_get_test_multidata(
TARGET eccodes_download_bufr_refs
NOCHECK
NAMES ${bufr_refs_to_download}
)
endif()

View File

@ -262,110 +262,6 @@ synop_multi_subset.bufr.desc.ref
aaen_55.bufr.ls.ref
syno_multi.bufr.header.ref
207003.bufr.json.ref
new_207003.bufr.ref
new_aaen_55.bufr.ref
new_aben_55.bufr.ref
new_ahws_139.bufr.ref
new_airc_142.bufr.ref
new_airc_144.bufr.ref
new_airs_57.bufr.ref
new_alws_139.bufr.ref
new_amda_144.bufr.ref
new_amsa_55.bufr.ref
new_amsb_55.bufr.ref
new_amse_55.bufr.ref
new_amsu_55.bufr.ref
new_amv2_87.bufr.ref
new_amv3_87.bufr.ref
new_asbh_139.bufr.ref
new_asbl_139.bufr.ref
new_asca_139.bufr.ref
new_asch_139.bufr.ref
new_ascs_139.bufr.ref
new_aseh_139.bufr.ref
new_asel_139.bufr.ref
new_ashs_139.bufr.ref
new_atap_55.bufr.ref
new_ateu_155.bufr.ref
new_atms_201.bufr.ref
new_atov_55.bufr.ref
new_avhm_87.bufr.ref
new_avhn_87.bufr.ref
new_avhr_58.bufr.ref
new_b002_95.bufr.ref
new_b002_96.bufr.ref
new_b003_56.bufr.ref
new_b004_145.bufr.ref
new_b005_87.bufr.ref
new_b006_96.bufr.ref
new_b007_31.bufr.ref
new_bssh_170.bufr.ref
new_bssh_176.bufr.ref
new_bssh_178.bufr.ref
new_bssh_180.bufr.ref
new_btem_109.bufr.ref
new_buoy_27.bufr.ref
new_cmwi_87.bufr.ref
new_cmwn_87.bufr.ref
new_cnow_28.bufr.ref
new_cori_156.bufr.ref
new_crit_202.bufr.ref
new_emsg_87.bufr.ref
new_euwv_87.bufr.ref
new_fy3a_154.bufr.ref
new_fy3b_154.bufr.ref
new_go15_87.bufr.ref
new_goee_87.bufr.ref
new_goes_87.bufr.ref
new_grst_26.bufr.ref
new_gst4_26.bufr.ref
new_hirb_55.bufr.ref
new_hirs_55.bufr.ref
new_ias1_240.bufr.ref
new_iasi_241.bufr.ref
new_itwt_233.bufr.ref
new_j2eo_216.bufr.ref
new_j2nb_216.bufr.ref
new_jaso_214.bufr.ref
new_meta_140.bufr.ref
new_mhen_55.bufr.ref
new_mhsa_55.bufr.ref
new_mhsb_55.bufr.ref
new_mhse_55.bufr.ref
new_modi_87.bufr.ref
new_modw_87.bufr.ref
new_monw_87.bufr.ref
new_mytemp.bufr.ref
new_new.bufr.ref
new_ocea_131.bufr.ref
new_ocea_132.bufr.ref
new_ocea_133.bufr.ref
new_ocea_21.bufr.ref
new_pgps_110.bufr.ref
new_pilo_91.bufr.ref
new_s4kn_165.bufr.ref
new_ship_13.bufr.ref
new_ship_19.bufr.ref
new_ship_9.bufr.ref
new_smin_49.bufr.ref
new_smis_49.bufr.ref
new_smiu_49.bufr.ref
new_smos_203.bufr.ref
new_sn4k_165.bufr.ref
new_soil_7.bufr.ref
new_ssbt_127.bufr.ref
new_stuk_7.bufr.ref
new_syno_1.bufr.ref
new_syno_3.bufr.ref
new_syno_4.bufr.ref
new_syno_multi.bufr.ref
new_synop_multi_subset.bufr.ref
new_temp_101.bufr.ref
new_temp_102.bufr.ref
new_temp_106.bufr.ref
new_tmr7_129.bufr.ref
new_tros_31.bufr.ref
new_wavb_134.bufr.ref
311001.bufr.ref
uegabe.bufr.num.ref
syno.bufr.out.ref

View File

@ -137,8 +137,6 @@ codetable[1] timeRangeIndicator ('5.table',tablesLocalDir,tablesMasterDir) = 1 :
unsigned[2] numberIncludedInAverage;
meta mybits bits(numberIncludedInAverage,0,12);
unsigned[1] numberMissingFromAveragesOrAccumulations;
unsigned[1] centuryOfReferenceTimeOfData;

View File

@ -1 +1,2 @@
1 CRRA Copernicus regional reanalysis
2 CRRA Copernicus regional reanalysis with expver

View File

@ -0,0 +1,7 @@
# CARRA/CERRA local
codetable[2] suiteName "grib2/crra_suiteName.table" : dump;
alias crraSuiteID = suiteName;
ksec1expver[4] experimentVersionNumber = "0002" : dump;
alias marsExpver = experimentVersionNumber ;

View File

@ -1,5 +1,7 @@
# (C) Copyright 2005- ECMWF.
# Copernicus regional reanalysis (CARRA/CERRA)
constant marsExpver = 'prod';
if (!defined(marsExpver)) {
constant marsExpver = 'prod';
}
include "grib2/products_crra.def"

View File

@ -1,5 +1,7 @@
# (C) Copyright 2005- ECMWF.
# Copernicus regional reanalysis (CARRA/CERRA)
constant marsExpver = 'test';
# Copernicus regional reanalysis test (CARRA/CERRA)
if (!defined(marsExpver)) {
constant marsExpver = 'test';
}
include "grib2/products_crra.def"

View File

@ -48,6 +48,7 @@ concept packingType (unknown) {
"spectral_ieee" = { dataRepresentationTemplateNumber = 50000; }
"grid_simple_log_preprocessing" = { dataRepresentationTemplateNumber = 61; }
"bifourier_complex" = { dataRepresentationTemplateNumber = 53; spectralType=2; }
"grid_run_length" = { dataRepresentationTemplateNumber = 200; }
} : dump;
template dataRepresentation "grib2/template.5.[dataRepresentationTemplateNumber:l].def";

View File

@ -50,6 +50,10 @@ if (bitMapIndicator == 255)
if (dataRepresentationTemplateNumber == 2 || dataRepresentationTemplateNumber == 3) {
transient missingValuesPresent = (missingValueManagementUsed != 0) : read_only;
}
if (dataRepresentationTemplateNumber == 200) {
# This template can have undefined values within its Data Section
transient missingValuesPresent = 1;
}
}
meta md5Section6 md5(offsetSection6,section6Length);

View File

@ -24,5 +24,7 @@ meta values data_apply_bitmap(codedValues,
alias data.packedValues = codedValues;
template statistics "common/statistics_grid.def";
template missing_values "common/missing_values_grid.def";
# This template can have undefined values within its Data Section
meta numberOfMissing count_missing(bitmap,unusedBitsInBitmap,numberOfDataPoints,one) : dump;
alias numberOfMissingValues=numberOfMissing;

View File

@ -148,7 +148,7 @@ foreach( test ${tests_extra} )
TYPE SCRIPT
CONDITION ENABLE_EXTRA_TESTS
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/${test}.sh
TEST_DEPENDS eccodes_download_gribs eccodes_download_bufrs )
TEST_DEPENDS eccodes_download_gribs eccodes_download_bufrs eccodes_download_bufr_refs )
endforeach()
# Tests which are conditional

View File

@ -15,9 +15,11 @@ tempGrib="out_surface_level.grib2"
${examples_dir}/c_grib_set_missing
# Check the keys have been set to MISSING
sf=`${tools_dir}/grib_get -p scaleFactorOfFirstFixedSurface $tempGrib`
[ "$sf" = "MISSING" ]
sf=`${tools_dir}/grib_get -p scaledValueOfFirstFixedSurface $tempGrib`
[ "$sf" = "MISSING" ]
if [ -f "${tools_dir}/grib_get" ]; then
sf=`${tools_dir}/grib_get -p scaleFactorOfFirstFixedSurface $tempGrib`
[ "$sf" = "MISSING" ]
sf=`${tools_dir}/grib_get -p scaledValueOfFirstFixedSurface $tempGrib`
[ "$sf" = "MISSING" ]
fi
rm -f $tempGrib

View File

@ -115,7 +115,7 @@ foreach( tool ${tests_extra} )
CONDITION HAVE_FORTRAN AND ENABLE_EXTRA_TESTS
RESOURCES bufr_read_scatterometer_f.ref
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/${tool}.sh
TEST_DEPENDS eccodes_download_gribs eccodes_download_bufrs )
TEST_DEPENDS eccodes_download_gribs eccodes_download_bufrs eccodes_download_bufr_refs )
endforeach()
# Test for CCSDS (AEC) packing
@ -123,7 +123,7 @@ ecbuild_add_test( TARGET eccodes_f_grib_set_packing
SOURCES grib_set_packing.f90
LINKER_LANGUAGE Fortran
LIBS eccodes_f90 eccodes
CONDITION HAVE_AEC AND HAVE_FORTRAN
CONDITION HAVE_BUILD_TOOLS AND HAVE_AEC AND HAVE_FORTRAN
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/grib_set_packing.sh )
# Executables without a shell script

View File

@ -86,44 +86,44 @@ char* codes_getenv(const char* name)
const char* old_name = name;
/* Test the most commonly used variables first */
if (STR_EQ(name, "ECCODES_SAMPLES_PATH"))
if (STR_EQUAL(name, "ECCODES_SAMPLES_PATH"))
old_name = "GRIB_SAMPLES_PATH";
else if (STR_EQ(name, "ECCODES_DEFINITION_PATH"))
else if (STR_EQUAL(name, "ECCODES_DEFINITION_PATH"))
old_name = "GRIB_DEFINITION_PATH";
else if (STR_EQ(name, "ECCODES_DEBUG"))
else if (STR_EQUAL(name, "ECCODES_DEBUG"))
old_name = "GRIB_API_DEBUG";
else if (STR_EQ(name, "ECCODES_FAIL_IF_LOG_MESSAGE"))
else if (STR_EQUAL(name, "ECCODES_FAIL_IF_LOG_MESSAGE"))
old_name = "GRIB_API_FAIL_IF_LOG_MESSAGE";
else if (STR_EQ(name, "ECCODES_GRIB_WRITE_ON_FAIL"))
else if (STR_EQUAL(name, "ECCODES_GRIB_WRITE_ON_FAIL"))
old_name = "GRIB_API_WRITE_ON_FAIL";
else if (STR_EQ(name, "ECCODES_GRIB_LARGE_CONSTANT_FIELDS"))
else if (STR_EQUAL(name, "ECCODES_GRIB_LARGE_CONSTANT_FIELDS"))
old_name = "GRIB_API_LARGE_CONSTANT_FIELDS";
else if (STR_EQ(name, "ECCODES_NO_ABORT"))
else if (STR_EQUAL(name, "ECCODES_NO_ABORT"))
old_name = "GRIB_API_NO_ABORT";
else if (STR_EQ(name, "ECCODES_GRIBEX_MODE_ON"))
else if (STR_EQUAL(name, "ECCODES_GRIBEX_MODE_ON"))
old_name = "GRIB_GRIBEX_MODE_ON";
else if (STR_EQ(name, "ECCODES_GRIB_IEEE_PACKING"))
else if (STR_EQUAL(name, "ECCODES_GRIB_IEEE_PACKING"))
old_name = "GRIB_IEEE_PACKING";
else if (STR_EQ(name, "ECCODES_IO_BUFFER_SIZE"))
else if (STR_EQUAL(name, "ECCODES_IO_BUFFER_SIZE"))
old_name = "GRIB_API_IO_BUFFER_SIZE";
else if (STR_EQ(name, "ECCODES_LOG_STREAM"))
else if (STR_EQUAL(name, "ECCODES_LOG_STREAM"))
old_name = "GRIB_API_LOG_STREAM";
else if (STR_EQ(name, "ECCODES_GRIB_NO_BIG_GROUP_SPLIT"))
else if (STR_EQUAL(name, "ECCODES_GRIB_NO_BIG_GROUP_SPLIT"))
old_name = "GRIB_API_NO_BIG_GROUP_SPLIT";
else if (STR_EQ(name, "ECCODES_GRIB_NO_SPD"))
else if (STR_EQUAL(name, "ECCODES_GRIB_NO_SPD"))
old_name = "GRIB_API_NO_SPD";
else if (STR_EQ(name, "ECCODES_GRIB_KEEP_MATRIX"))
else if (STR_EQUAL(name, "ECCODES_GRIB_KEEP_MATRIX"))
old_name = "GRIB_API_KEEP_MATRIX";
else if (STR_EQ(name, "_ECCODES_ECMWF_TEST_DEFINITION_PATH"))
else if (STR_EQUAL(name, "_ECCODES_ECMWF_TEST_DEFINITION_PATH"))
old_name = "_GRIB_API_ECMWF_TEST_DEFINITION_PATH";
else if (STR_EQ(name, "_ECCODES_ECMWF_TEST_SAMPLES_PATH"))
else if (STR_EQUAL(name, "_ECCODES_ECMWF_TEST_SAMPLES_PATH"))
old_name = "_GRIB_API_ECMWF_TEST_SAMPLES_PATH";
else if (STR_EQ(name, "ECCODES_GRIB_JPEG"))
else if (STR_EQUAL(name, "ECCODES_GRIB_JPEG"))
old_name = "GRIB_JPEG";
else if (STR_EQ(name, "ECCODES_GRIB_DUMP_JPG_FILE"))
else if (STR_EQUAL(name, "ECCODES_GRIB_DUMP_JPG_FILE"))
old_name = "GRIB_DUMP_JPG_FILE";
else if (STR_EQ(name, "ECCODES_PRINT_MISSING"))
else if (STR_EQUAL(name, "ECCODES_PRINT_MISSING"))
old_name = "GRIB_PRINT_MISSING";
result = getenv(old_name);
@ -194,3 +194,23 @@ int codes_flush_sync_close_file(FILE* f)
}
return GRIB_SUCCESS;
}
// Return 1 if input date is valid. Otherwise 0
int is_date_valid(long year, long month, long day, long hour, long minute, double second)
{
// Convert input date to Julian number
double result = 0; // Julian number in units of days
long year1, month1, day1, hour1, minute1, lSecond1;
// For validating the date/time, we specify seconds as an integer
long lSecond = (long)second;
grib_datetime_to_julian(year, month, day, hour, minute, lSecond, &result);
// Check conversion worked by going other way
grib_julian_to_datetime(result, &year1, &month1, &day1, &hour1, &minute1, &lSecond1);
if (year1 != year || month1 != month || day1 != day || minute1 != minute || lSecond1 != lSecond) {
return 0; // bad date
}
return 1;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
#ifdef ECCODES_ON_WINDOWS
#include <stdint.h>
#include <stdint.h>
#endif
/* action.cc */
@ -1075,7 +1075,7 @@ void grib_math_delete(grib_context* c, grib_math* m);
grib_math* grib_math_new(grib_context* c, const char* formula, int* err);
/* grib_hash_keys.cc*/
const struct grib_keys_hash* grib_keys_hash_get(const char *str, size_t len);
const struct grib_keys_hash* grib_keys_hash_get(const char* str, size_t len);
grib_itrie* grib_hash_keys_new(grib_context* c, int* count);
void grib_hash_keys_delete(grib_itrie* t);
int grib_hash_keys_get_id(grib_itrie* t, const char* key);
@ -1341,13 +1341,13 @@ int grib_nearest_get_radius(grib_handle* h, double* radiusInKm);
void grib_binary_search(const double xx[], const size_t n, double x, size_t* ju, size_t* jl);
int grib_nearest_find_multiple(const grib_handle* h, int is_lsm, const double* inlats, const double* inlons, long npoints, double* outlats, double* outlons, double* values, double* distances, int* indexes);
int grib_nearest_find_generic(grib_nearest* nearest, grib_handle* h, double inlat, double inlon, unsigned long flags,
const char* values_keyname, const char* Ni_keyname, const char* Nj_keyname,
double** out_lats,
int* out_lats_count,
double** out_lons,
int* out_lons_count,
double** out_distances,
double* outlats, double* outlons, double* values, double* distances, int* indexes, size_t* len);
const char* values_keyname, const char* Ni_keyname, const char* Nj_keyname,
double** out_lats,
int* out_lats_count,
double** out_lons,
int* out_lons_count,
double** out_distances,
double* outlats, double* outlons, double* values, double* distances, int* indexes, size_t* len);
/* grib_nearest_class.cc*/
grib_nearest* grib_nearest_factory(grib_handle* h, grib_arguments* args);
@ -1427,6 +1427,7 @@ int path_is_directory(const char* filename);
char* codes_getenv(const char* name);
int codes_check_grib_ieee_packing_value(int value);
int codes_flush_sync_close_file(FILE* f);
int is_date_valid(long year, long month, long day, long hour, long minute, double second);
/* grib_util.cc*/
grib_handle* grib_util_sections_copy(grib_handle* hfrom, grib_handle* hto, int what, int* err);
@ -1467,8 +1468,8 @@ int string_ends_with(const char* str1, const char* str2);
int string_count_char(const char* str, char c);
const char* codes_get_product_name(ProductKind product);
const char* grib_get_type_name(int type);
char* string_replace_char(char *str, char oldc, char newc);
void string_remove_char(char * str, char c);
char* string_replace_char(char* str, char oldc, char newc);
void string_remove_char(char* str, char c);
/* functions.cc*/
long grib_op_eq(long a, long b);

View File

@ -191,6 +191,10 @@ static int value_count(grib_accessor* a, long* count)
#include <libaec.h>
#ifndef LIBAEC_DLL_EXPORTED
#error Version of libaec appears to be too old. Please upgrade.
#endif
static const char* aec_get_error_message(int code)
{
if (code == AEC_MEM_ERROR) return "AEC_MEM_ERROR";

View File

@ -183,6 +183,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
double level_scale_factor = 0;
double* levels = NULL;
unsigned char* buf = NULL;
double missingValue = 9999.0;
if ((err = grib_get_long_internal(gh, self->seclen, &seclen)) != GRIB_SUCCESS)
return err;
@ -196,6 +197,8 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
return err;
if ((err = grib_get_long_internal(gh, self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS)
return err;
if ((err = grib_get_double(gh, "missingValue", &missingValue)) != GRIB_SUCCESS)
return err;
level_values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * number_of_level_values);
level_values_size = number_of_level_values;
@ -206,7 +209,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
number_of_compressed_values = ((seclen - 5) * 8) / bits_per_value;
if (number_of_compressed_values == 0 || max_level_value == 0) {
for (i = 0; i < number_of_values; i++) {
val[i] = GRIB_MISSING_DOUBLE;
val[i] = missingValue;
}
return GRIB_SUCCESS;
}
@ -220,7 +223,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
}
level_scale_factor = grib_power(-decimal_scale_factor, 10.0);
levels = (double*)grib_context_malloc_clear(a->context, sizeof(double) * (number_of_level_values + 1));
levels[0] = 0;
levels[0] = missingValue;
for (i = 0; i < number_of_level_values; i++) {
levels[i + 1] = level_values[i] * level_scale_factor;
}

View File

@ -324,8 +324,8 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len)
lats = (double*)grib_context_malloc(c, sizeof(double) * N * 2);
if (!lats) {
grib_context_log(c, GRIB_LOG_FATAL,
"global_gaussian pack_long: Memory allocation error: %ld bytes", sizeof(double) * N * 2);
grib_context_log(c, GRIB_LOG_ERROR,
"global_gaussian pack_long: Memory allocation error: %zu bytes", sizeof(double) * N * 2);
return GRIB_OUT_OF_MEMORY;
}
if ((ret = grib_get_gaussian_latitudes(N, lats)) != GRIB_SUCCESS)

View File

@ -236,7 +236,7 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len)
values = (double*)grib_context_malloc_clear(a->context, sizeof(double) * size);
if (!values) {
grib_context_log(a->context, GRIB_LOG_FATAL, "%s: Memory allocation error: %zu bytes", a->name, size);
grib_context_log(a->context, GRIB_LOG_ERROR, "%s: Memory allocation error: %zu bytes", a->name, size);
return GRIB_OUT_OF_MEMORY;
}
if ((ret = grib_get_double_array_internal(grib_handle_of_accessor(a), self->values, values, &size)) != GRIB_SUCCESS)

File diff suppressed because it is too large Load Diff

View File

@ -201,7 +201,7 @@ extern int pthread_mutexattr_settype(pthread_mutexattr_t* attr, int type);
#endif
/* Return true if two strings are equal */
#define STR_EQ(a, b) (strcmp((a), (b)) == 0)
#define STR_EQUAL(a, b) (strcmp((a), (b)) == 0)
#include "grib_api.h"

View File

@ -489,7 +489,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm
self->empty = 0;
values = (char**)grib_context_malloc_clear(c, size * sizeof(char*));
if (!values) {
grib_context_log(c, GRIB_LOG_FATAL, "unable to allocate %d bytes", (int)size);
grib_context_log(c, GRIB_LOG_ERROR, "unable to allocate %zu bytes", size);
return;
}

View File

@ -621,7 +621,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm
self->empty = 0;
values = (char**)grib_context_malloc_clear(c, size * sizeof(char*));
if (!values) {
grib_context_log(c, GRIB_LOG_FATAL, "Memory allocation error: %zu bytes", size);
grib_context_log(c, GRIB_LOG_ERROR, "Memory allocation error: %zu bytes", size);
return;
}
@ -682,7 +682,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment)
value = (char*)grib_context_malloc_clear(c, size);
if (!value) {
grib_context_log(c, GRIB_LOG_FATAL, "Memory allocation error: %zu bytes", size);
grib_context_log(c, GRIB_LOG_ERROR, "Memory allocation error: %zu bytes", size);
return;
}

View File

@ -557,7 +557,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm
values = (char**)grib_context_malloc_clear(c, size * sizeof(char*));
if (!values) {
grib_context_log(c, GRIB_LOG_FATAL, "unable to allocate %d bytes", (int)size);
grib_context_log(c, GRIB_LOG_ERROR, "unable to allocate %zu bytes", size);
return;
}
@ -615,7 +615,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment)
value = (char*)grib_context_malloc_clear(c, size);
if (!value) {
grib_context_log(c, GRIB_LOG_FATAL, "unable to allocate %d bytes", (int)size);
grib_context_log(c, GRIB_LOG_ERROR, "unable to allocate %zu bytes", size);
return;
}

View File

@ -672,7 +672,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm
values = (char**)grib_context_malloc_clear(c, size * sizeof(char*));
if (!values) {
grib_context_log(c, GRIB_LOG_FATAL, "unable to allocate %d bytes", (int)size);
grib_context_log(c, GRIB_LOG_ERROR, "unable to allocate %zu bytes", size);
return;
}
@ -731,7 +731,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment)
value = (char*)grib_context_malloc_clear(c, size);
if (!value) {
grib_context_log(c, GRIB_LOG_FATAL, "unable to allocate %d bytes", (int)size);
grib_context_log(c, GRIB_LOG_ERROR, "unable to allocate %zu bytes", size);
return;
}

View File

@ -614,7 +614,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm
values = (char**)grib_context_malloc_clear(c, size * sizeof(char*));
if (!values) {
grib_context_log(c, GRIB_LOG_FATAL, "Memory allocation error: %zu bytes", size);
grib_context_log(c, GRIB_LOG_ERROR, "Memory allocation error: %zu bytes", size);
return;
}
@ -672,7 +672,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment)
value = (char*)grib_context_malloc_clear(c, size);
if (!value) {
grib_context_log(c, GRIB_LOG_FATAL, "Memory allocation error: %zu bytes", size);
grib_context_log(c, GRIB_LOG_ERROR, "Memory allocation error: %zu bytes", size);
return;
}

View File

@ -572,7 +572,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm
values = (char**)grib_context_malloc_clear(c, size * sizeof(char*));
if (!values) {
grib_context_log(c, GRIB_LOG_FATAL, "Memory allocation error: %zu bytes", size);
grib_context_log(c, GRIB_LOG_ERROR, "Memory allocation error: %zu bytes", size);
return;
}

View File

@ -350,7 +350,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm
values = (char**)grib_context_malloc_clear(c, size * sizeof(char*));
if (!values) {
grib_context_log(c, GRIB_LOG_FATAL, "Memory allocation error: %zu bytes", size);
grib_context_log(c, GRIB_LOG_ERROR, "Memory allocation error: %zu bytes", size);
return;
}
@ -416,7 +416,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment)
value = (char*)grib_context_malloc_clear(c, size);
if (!value) {
grib_context_log(c, GRIB_LOG_FATAL, "Memory allocation error: %zu bytes", size);
grib_context_log(c, GRIB_LOG_ERROR, "Memory allocation error: %zu bytes", size);
return;
}

View File

@ -397,7 +397,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm
values = (char**)grib_context_malloc_clear(c, size * sizeof(char*));
if (!values) {
grib_context_log(c, GRIB_LOG_FATAL, "Memory allocation error: %zu bytes", size);
grib_context_log(c, GRIB_LOG_ERROR, "Memory allocation error: %zu bytes", size);
return;
}
@ -458,7 +458,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment)
* if (size==0) return;
* value=(char*)grib_context_malloc_clear(a->context,size);
* if (!value) {
* grib_context_log(a->context,GRIB_LOG_FATAL,"unable to allocate %d bytes",(int)size);
* grib_context_log(a->context,GRIB_LOG_ERROR,"unable to allocate %d bytes",(int)size);
* return;
* }
*/

View File

@ -308,7 +308,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment)
ecc__grib_get_string_length(a, &size);
value = (char*)grib_context_malloc_clear(a->context, size);
if (!value) {
grib_context_log(a->context, GRIB_LOG_FATAL, "unable to allocate %d bytes", (int)size);
grib_context_log(a->context, GRIB_LOG_ERROR, "unable to allocate %zu bytes", size);
return;
}
err = grib_unpack_string(a, value, &size);
@ -630,7 +630,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm
values = (char**)grib_context_malloc_clear(c, size * sizeof(char*));
if (!values) {
grib_context_log(c, GRIB_LOG_FATAL, "unable to allocate %d bytes", (int)size);
grib_context_log(c, GRIB_LOG_ERROR, "unable to allocate %zu bytes", size);
return;
}

View File

@ -9,9 +9,8 @@
*/
/***************************************************************************
* Jean Baptiste Filippi - 01.11.2005
* Enrico Fucile
* *
* Jean Baptiste Filippi - 01.11.2005 *
* Enrico Fucile *
***************************************************************************/
#include "grib_api_internal.h"
@ -1375,25 +1374,25 @@ int codes_check_message_footer(const void* bytes, size_t length, ProductKind pro
int grib_get_message_size(const grib_handle* ch, size_t* size)
{
long totalLength = 0;
int ret = 0;
int err = 0;
grib_handle* h = (grib_handle*)ch;
*size = h->buffer->ulength;
ret = grib_get_long(h, "totalLength", &totalLength);
if (!ret)
err = grib_get_long(h, "totalLength", &totalLength);
if (!err)
*size = totalLength;
return ret;
return err;
}
int grib_get_message(const grib_handle* ch, const void** msg, size_t* size)
{
long totalLength = 0;
int ret = 0;
int err = 0;
grib_handle* h = (grib_handle*)ch;
*msg = h->buffer->data;
*size = h->buffer->ulength;
ret = grib_get_long(h, "totalLength", &totalLength);
if (!ret)
err = grib_get_long(h, "totalLength", &totalLength);
if (!err)
*size = totalLength;
if (h->context->gts_header_on && h->gts_header) {
@ -1406,20 +1405,20 @@ int grib_get_message(const grib_handle* ch, const void** msg, size_t* size)
int grib_get_message_headers(grib_handle* h, const void** msg, size_t* size)
{
int ret = 0;
int err = 0;
size_t endOfHeadersMarker;
*msg = h->buffer->data;
*size = h->buffer->ulength;
if ((ret = grib_get_offset(h, "endOfHeadersMarker", &endOfHeadersMarker)) != GRIB_SUCCESS) {
grib_context_log(h->context, GRIB_LOG_FATAL,
"grib_get_message_headers unable to get offset of endOfHeadersMarker");
return ret;
if ((err = grib_get_offset(h, "endOfHeadersMarker", &endOfHeadersMarker)) != GRIB_SUCCESS) {
grib_context_log(h->context, GRIB_LOG_ERROR,
"grib_get_message_headers: unable to get offset of endOfHeadersMarker");
return err;
}
*size = endOfHeadersMarker;
return ret;
return err;
}
grib_handle* grib_handle_new(grib_context* c)

View File

@ -26,6 +26,11 @@ static int ecc_jasper_initialise()
int jaserr = 0;
jas_conf_clear();
jas_conf_set_max_mem_usage(jas_get_total_mem_size());
#if defined GRIB_PTHREADS || defined GRIB_OMP_THREADS
jas_conf_set_multithread(1);
#endif
jaserr = jas_init_library();
if (jaserr) return jaserr;
jaserr = jas_init_thread();

View File

@ -11,8 +11,6 @@
#include "grib_api_internal.h"
#include <float.h>
#define STR_EQUAL(s1, s2) (strcmp((s1), (s2)) == 0)
typedef enum
{
eROUND_ANGLE_UP,
@ -982,14 +980,20 @@ grib_handle* grib_util_set_spec2(grib_handle* h,
fprintf(stderr, "ECCODES DEBUG grib_util: input_decimal_scale_factor = %ld\n", input_decimal_scale_factor);
}
/* ECC-1201
TODO: make sure input packing type is preserved */
/* ECC-1201, ECC-1529, ECC-1530
Make sure input packing type is preserved */
if (packing_spec->packing == GRIB_UTIL_PACKING_SAME_AS_INPUT &&
packing_spec->packing_type == GRIB_UTIL_PACKING_TYPE_SAME_AS_INPUT)
{
if (STR_EQUAL(input_packing_type, "grid_ieee")) {
SET_STRING_VALUE("packingType", input_packing_type);
}
if (STR_EQUAL(input_packing_type, "grid_ccsds")) {
setCcsdsPacking = 1;
}
if (STR_EQUAL(input_packing_type, "grid_second_order")) {
setSecondOrder = 1;
}
}
/*if ( (*err=check_values(data_values, data_values_count))!=GRIB_SUCCESS ) {
@ -1280,7 +1284,7 @@ grib_handle* grib_util_set_spec2(grib_handle* h,
* Reason 1: It is not available in GRIB1 and so we have to wait until we change edition
* Reason 2: It has to be done AFTER we set the data values
*/
if (strcmp(input_packing_type, "grid_jpeg") && !strcmp(input_packing_type, "grid_simple"))
if (strcmp(input_packing_type, "grid_jpeg"))
setJpegPacking = 1;
break;
case GRIB_UTIL_PACKING_TYPE_CCSDS:

View File

@ -44,6 +44,7 @@ list(APPEND test_c_bins
grib_sh_ieee64
grib_ieee
grib_set_bytes
grib_copy_message
grib_packing_order
grib_sh_imag
grib_sh_spectral_complex
@ -239,6 +240,7 @@ if( HAVE_BUILD_TOOLS )
grib_grid_mercator
grib_global
grib_concept
grib_copy_message
grib_decimalPrecision
grib_bitsPerValue
grib_get_fail
@ -311,7 +313,8 @@ if( HAVE_BUILD_TOOLS )
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/${test}.sh
RESOURCES asca_139.t1.ref
TEST_DEPENDS eccodes_download_gribs eccodes_download_tigge_gribs
eccodes_download_bufrs eccodes_download_metars eccodes_download_gts )
eccodes_download_bufrs eccodes_download_bufr_refs
eccodes_download_metars eccodes_download_gts )
endforeach()
if( HAVE_FORTRAN AND ENABLE_EXTRA_TESTS )
@ -348,7 +351,7 @@ if( HAVE_BUILD_TOOLS )
TYPE SCRIPT
CONDITION NOT ECCODES_ON_WINDOWS AND ENABLE_EXTRA_TESTS
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/bufr_ecc-1288.sh
TEST_DEPENDS eccodes_download_bufrs )
TEST_DEPENDS eccodes_download_bufrs eccodes_download_bufr_refs )
if( ENABLE_EXTRA_TESTS AND HAVE_ECCODES_THREADS )

View File

@ -21,6 +21,11 @@ outfile2=temp.$label.2
rm -f $outfile1 $outfile2
# Convert a non-constant grib2 file (Note: not using -r)
grib2_sample=$ECCODES_SAMPLES_PATH/gg_sfc_grib2.tmpl
${tools_dir}/grib_set -s packingType=grid_ccsds $grib2_sample $outfile1
${tools_dir}/grib_compare -c data:n $grib2_sample $outfile1
# ECC-1263
# ---------

View File

@ -0,0 +1,57 @@
/*
* (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 <stdio.h>
#undef NDEBUG
#include <assert.h>
#include "eccodes.h"
int main(int argc, char* argv[])
{
FILE* in = NULL;
codes_handle* source_handle = NULL;
int err = 0;
size_t totalLength = 0, size = 0;
unsigned char* buffer = NULL;
codes_handle* new_handle = NULL;
assert (argc == 3);
in = fopen(argv[1], "rb");
assert(in);
source_handle = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err);
assert(source_handle);
// How big is the input GRIB message?
CODES_CHECK(codes_get_message_size(source_handle, &totalLength), 0);
// Allocate a buffer large enough to hold the message
buffer = (unsigned char*)malloc(totalLength);
size = totalLength;
// Take a copy of the message into buffer. Now we own it
CODES_CHECK(codes_get_message_copy(source_handle, buffer, &size), 0);
assert(size == totalLength);
codes_handle_delete(source_handle);
// Now buffer contains a copy of the message
new_handle = codes_handle_new_from_message(0, buffer, totalLength);
assert(new_handle);
// Change something and write it out
CODES_CHECK(codes_set_long(new_handle, "hour", 18), 0);
CODES_CHECK(codes_write_message(new_handle, argv[2], "w"), 0);
codes_handle_delete(new_handle);
free(buffer);
fclose(in);
return 0;
}

23
tests/grib_copy_message.sh Executable file
View File

@ -0,0 +1,23 @@
#!/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="grib_copy_message_test"
temp=temp.$label.grib
infile=$data_dir/sample.grib2
$EXEC ${test_dir}/grib_copy_message $infile $temp
# The hour key was changed but nothing else
${tools_dir}/grib_compare -b hour $infile $temp
# Clean up test outputs
rm -f $temp

View File

@ -62,8 +62,7 @@ regular_latlon_surface.grib1
regular_latlon_surface.grib2
"
for file in $files
do
for file in $files; do
[ -f "$file" ]
echo $file >> $tempLog
${tools_dir}/grib_ls -l 40,28 $file | grep index | awk '{print $4;}' >> $tempLog
@ -72,7 +71,8 @@ done
diff $tempLog ls.log
rm -f $tempLog
# Test for bug GRIB-56
echo "Test for bug GRIB-56..."
# ------------------------------
${tools_dir}/grib_set -s typeOfLevel=depthBelowLandLayer,topLevel=missing regular_latlon_surface.grib1 tmp_rlls.grib1
${tools_dir}/grib_ls -plevels tmp_rlls.grib1 | grep MISSING>/dev/null
@ -80,18 +80,23 @@ ${tools_dir}/grib_set -s typeOfLevel=depthBelowLandLayer,bottomLevel=missing reg
${tools_dir}/grib_ls -plevels tmp_rlls.grib1 | grep MISSING>/dev/null
rm -f tmp_rlls.grib1
# GRIB-305. GRIB edition 1 file with one large message
echo "GRIB-305. GRIB edition 1 file with one large message..."
# ----------------------------------------------------------
if [ -f "sst_globus0083.grib" ]; then
${tools_dir}/grib_ls sst_globus0083.grib > /dev/null
${tools_dir}/grib_ls sst_globus0083.grib > /dev/null
fi
# GRIB-387 printing key of type byte
echo "GRIB-387 printing key of type byte..."
# ----------------------------------------------------------
${tools_dir}/grib_ls -p uuidOfVGrid test_uuid.grib2 > /dev/null
type=`${tools_dir}/grib_get -wcount=1 -p typeOfLevel test_uuid.grib2`
[ "$type" = "generalVertical" ]
# GRIB-213 nearest with land-sea mask
echo "GRIB-213 nearest with land-sea mask..."
# ----------------------------------------------------------
temp_ls=temp.grib_ls.grib-213.txt
${tools_dir}/grib_ls -l 85,13,1,reduced_gaussian_lsm.grib1 reduced_gaussian_surface.grib1 >$temp_ls
grep -q 'Point chosen #3 index=21 .* distance=11\.' $temp_ls
@ -100,7 +105,8 @@ ${tools_dir}/grib_ls -l 53,2,1,reduced_gaussian_lsm.grib1 reduced_gaussian_surfa
grep -q 'Point chosen #2 index=749 .* distance=204\.' $temp_ls
# ECC-278: grib_ls -n namespace
echo "ECC-278: grib_ls -n namespace..."
# ----------------------------------------------------------
${tools_dir}/grib_ls -n geography $ECCODES_SAMPLES_PATH/reduced_ll_sfc_grib2.tmpl
${tools_dir}/grib_ls -n data $sample_g1
@ -118,7 +124,9 @@ diff $temp1 $temp2
# Section pointers
grib_check_key_equals $sample_g2 'section0Pointer,section1Pointer,section3Pointer,section4Pointer' '0_16 16_21 37_72 109_34'
# constraints: -w option
echo "Test constraints: -w option..."
# ----------------------------------------------------------
file=tigge_pf_ecmwf.grib2 # Has 38 messages
${tools_dir}/grib_ls -w count!=1 $file > $temp_ls
grep -q "37 of 38 messages" $temp_ls
@ -147,6 +155,31 @@ grep -q "0 of 38 messages" $temp_ls
${tools_dir}/grib_ls -w units!=K $file > $temp_ls
grep -q "30 of 38 messages" $temp_ls
file=mixed.grib # Has 14 messages
${tools_dir}/grib_ls -w packingType=grid_simple,gridType=regular_ll/regular_gg $file > $temp_ls
grep -q "12 of 14 messages" $temp_ls
${tools_dir}/grib_ls -w packingType=grid_simple/grid_simple_matrix,gridType=regular_ll/regular_gg $file > $temp_ls
grep -q "12 of 14 messages" $temp_ls
${tools_dir}/grib_ls -w typeOfLevel=surface,centre=7 $file > $temp_ls
grep -q "3 of 14 messages" $temp_ls
${tools_dir}/grib_ls -w shortName=t/10u,gridType=regular_gg $file > $temp_ls
grep -q "5 of 14 messages" $temp_ls
# ECC-1528: Try some invalid values for the count constraint
for cval in -1 0 xx; do
set +e
rm -f $temp_ls
${tools_dir}/grib_ls -w count=$cval $file > $temp_ls 2>&1
status=$?
set -e
[ $status -ne 0 ]
grep -q "Invalid value for key 'count'" $temp_ls
done
# Clean up
rm -f $temp1 $temp2

View File

@ -169,6 +169,14 @@ grib_check_key_equals $infile packingType grid_second_order
${tools_dir}/grib_set -d1 $infile $temp1
grib_check_key_equals $temp1 packingType grid_simple
infile=$ECCODES_SAMPLES_PATH/GRIB1.tmpl
${tools_dir}/grib_set -r -s packingType=grid_second_order $infile $temp1
grib_check_key_equals $temp1 packingType grid_simple
infile=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
${tools_dir}/grib_set -r -s packingType=grid_second_order $infile $temp1
grib_check_key_equals $temp1 packingType grid_simple
# Clean up
rm -f $temp_stat1 $temp_stat2

View File

@ -71,7 +71,8 @@ GRIB2_INPUTS="
${data_dir}/test_file.grib2
${data_dir}/sample.grib2"
if [ $HAVE_JPEG -eq 1 ]; then
# There is a problem with multi-threading and Jasper versions > 2
if [ $HAVE_JPEG -eq 1 -a $HAVE_LIBJASPER -eq 0 ]; then
echo "Adding extra files (HAVE_JPEG=1)"
GRIB2_INPUTS="${data_dir}/jpeg.grib2 ${data_dir}/reduced_gaussian_surface_jpeg.grib2 "$GRIB2_INPUTS
fi

View File

@ -73,5 +73,30 @@ status=$?
set -e
[ $status -ne 0 ]
# ECC-1532
# ---------
# By default crraLocalVersion=1 which does not allow expver to be set
# because it is a constant (prod or test)
set +e
${tools_dir}/grib_set -s \
productionStatusOfProcessedData=10,grib2LocalSectionPresent=1,marsExpver=coco \
$grib2_sample $temp1
status=$?
set -e
[ $status -ne 0 ]
# ECC-1532
# crraLocalVersion=2 has a coded key for experimentVersionNumber
${tools_dir}/grib_set -s \
productionStatusOfProcessedData=10,grib2LocalSectionPresent=1,crraLocalVersion=2,marsExpver=coco \
$grib2_sample $temp1
grib_check_key_equals $temp1 'marsExpver,mars.expver' 'coco coco'
${tools_dir}/grib_set -s \
productionStatusOfProcessedData=11,grib2LocalSectionPresent=1,crraLocalVersion=2,experimentVersionNumber=0078 \
$grib2_sample $temp1
grib_check_key_equals $temp1 'marsExpver,mars.expver' '0078 0078'
# Clean up
rm -f $temp1 $temp2 $tempSample

View File

@ -11,25 +11,24 @@
#include "grib_api_internal.h"
#include "eccodes.h"
#define STR_EQUAL(s1, s2) (strcmp((s1), (s2)) == 0)
static int get_packing_type_code(const char* packingType)
{
int result = GRIB_UTIL_PACKING_TYPE_GRID_SIMPLE;
if (packingType == NULL)
return result;
return GRIB_UTIL_PACKING_TYPE_SAME_AS_INPUT;
if (STR_EQUAL(packingType, "grid_jpeg"))
result = GRIB_UTIL_PACKING_TYPE_JPEG;
if (STR_EQUAL(packingType, "grid_ccsds"))
result = GRIB_UTIL_PACKING_TYPE_CCSDS;
return GRIB_UTIL_PACKING_TYPE_JPEG;
else if (STR_EQUAL(packingType, "grid_ccsds"))
return GRIB_UTIL_PACKING_TYPE_CCSDS;
else if (STR_EQUAL(packingType, "grid_simple"))
result = GRIB_UTIL_PACKING_TYPE_GRID_SIMPLE;
return GRIB_UTIL_PACKING_TYPE_GRID_SIMPLE;
else if (STR_EQUAL(packingType, "grid_second_order"))
result = GRIB_UTIL_PACKING_TYPE_GRID_SECOND_ORDER;
return GRIB_UTIL_PACKING_TYPE_GRID_SECOND_ORDER;
else if (STR_EQUAL(packingType, "grid_ieee"))
result = GRIB_UTIL_PACKING_TYPE_IEEE;
return GRIB_UTIL_PACKING_TYPE_IEEE;
Assert(!"Invalid packingType");
return result;
}
@ -47,8 +46,8 @@ static void test_reduced_gg(int remove_local_def, int edition, const char* packi
const void* buffer = NULL;
char gridType[128] = {0,};
codes_handle* handle = 0;
codes_handle* finalh = 0;
grib_handle* handle = 0;
grib_handle* finalh = 0;
grib_util_grid_spec spec = {0,};
grib_util_packing_spec packing_spec = {0,};
@ -70,6 +69,9 @@ static void test_reduced_gg(int remove_local_def, int edition, const char* packi
CODES_CHECK(grib_get_size(handle, "values", &inlen), 0);
values = (double*)malloc(sizeof(double) * inlen);
CODES_CHECK(grib_get_double_array(handle, "values", values, &inlen), 0);
// make sure values are not constant
values[0] = 4.4;
values[1] = 5.5;
for (i = 0; i < inlen; ++i) {
values[i] *= 1.10;
}
@ -90,7 +92,10 @@ static void test_reduced_gg(int remove_local_def, int edition, const char* packi
packing_spec.packing_type = get_packing_type_code(packingType);
packing_spec.bitsPerValue = 24;
packing_spec.accuracy = GRIB_UTIL_ACCURACY_USE_PROVIDED_BITS_PER_VALUES;
packing_spec.packing = GRIB_UTIL_PACKING_USE_PROVIDED;
if (packingType)
packing_spec.packing = GRIB_UTIL_PACKING_USE_PROVIDED;
else
packing_spec.packing = GRIB_UTIL_PACKING_SAME_AS_INPUT;
/*Extra settings
packing_spec.extra_settings_count++;
@ -112,7 +117,7 @@ static void test_reduced_gg(int remove_local_def, int edition, const char* packi
/* Try some invalid inputs and check it is handled */
{
codes_handle* h2 = 0;
grib_handle* h2 = 0;
packing_spec.accuracy = 999;
h2 = grib_util_set_spec(handle, &spec, &packing_spec, set_spec_flags, values, outlen, &err);
Assert(err == GRIB_INTERNAL_ERROR);
@ -158,18 +163,18 @@ static void test_regular_ll(int remove_local_def, int edition, const char* packi
char gridType[128] = {0,};
long input_edition = 0;
codes_handle* handle = 0;
codes_handle* finalh = 0;
grib_handle* handle = 0;
grib_handle* finalh = 0;
grib_util_grid_spec spec = {0,};
grib_util_packing_spec packing_spec = {0,};
Assert(input_filename);
in = fopen(input_filename, "rb");
Assert(in);
handle = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err);
handle = grib_handle_new_from_file(0, in, &err);
Assert(handle);
CODES_CHECK(codes_get_long(handle, "edition", &input_edition), 0);
CODES_CHECK(grib_get_long(handle, "edition", &input_edition), 0);
CODES_CHECK(grib_get_string(handle, "gridType", gridType, &slen), 0);
if (!STR_EQUAL(gridType, "regular_ll")) {
@ -180,9 +185,12 @@ static void test_regular_ll(int remove_local_def, int edition, const char* packi
out = fopen(output_filename, "wb");
Assert(out);
CODES_CHECK(codes_get_size(handle, "values", &inlen), 0);
CODES_CHECK(grib_get_size(handle, "values", &inlen), 0);
values = (double*)malloc(sizeof(double) * inlen);
CODES_CHECK(codes_get_double_array(handle, "values", values, &inlen), 0);
CODES_CHECK(grib_get_double_array(handle, "values", values, &inlen), 0);
// make sure values are not constant
values[0] = 4.4;
values[1] = 5.5;
spec.grid_type = GRIB_UTIL_GRID_SPEC_REGULAR_LL;
spec.Nj = 14;
@ -201,7 +209,10 @@ static void test_regular_ll(int remove_local_def, int edition, const char* packi
packing_spec.packing_type = get_packing_type_code(packingType);
packing_spec.bitsPerValue = 24;
packing_spec.accuracy = GRIB_UTIL_ACCURACY_USE_PROVIDED_BITS_PER_VALUES;
packing_spec.packing = GRIB_UTIL_PACKING_USE_PROVIDED;
if (packingType)
packing_spec.packing = GRIB_UTIL_PACKING_USE_PROVIDED;
else
packing_spec.packing = GRIB_UTIL_PACKING_SAME_AS_INPUT;
packing_spec.extra_settings_count++;
packing_spec.extra_settings[0].type = GRIB_TYPE_LONG;
@ -215,7 +226,7 @@ static void test_regular_ll(int remove_local_def, int edition, const char* packi
packing_spec.deleteLocalDefinition = 1;
}
finalh = codes_grib_util_set_spec(
finalh = grib_util_set_spec(
handle,
&spec,
&packing_spec,
@ -232,19 +243,19 @@ static void test_regular_ll(int remove_local_def, int edition, const char* packi
if (input_edition == 1) {
const double expected_lat1 = 60.001;
double lat1 = 0;
CODES_CHECK(codes_get_double(finalh, "latitudeOfFirstGridPointInDegrees", &lat1), 0);
CODES_CHECK(grib_get_double(finalh, "latitudeOfFirstGridPointInDegrees", &lat1), 0);
Assert(fabs(lat1 - expected_lat1) < 1e-10);
}
/* Write out the message to the output file */
CODES_CHECK(codes_get_message(finalh, &buffer, &size), 0);
CODES_CHECK(grib_get_message(finalh, &buffer, &size), 0);
CODES_CHECK(codes_check_message_header(buffer, size, PRODUCT_GRIB), 0);
CODES_CHECK(codes_check_message_footer(buffer, size, PRODUCT_GRIB), 0);
if (fwrite(buffer, 1, size, out) != size) {
Assert(0);
}
codes_handle_delete(handle);
codes_handle_delete(finalh);
grib_handle_delete(handle);
grib_handle_delete(finalh);
free(values);
fclose(in);
fclose(out);
@ -266,13 +277,13 @@ static void test_grid_complex_spatial_differencing(int remove_local_def, int edi
char gridType[128] = {0,};
double theMax,theMin,theAverage;
codes_handle *handle = 0;
codes_handle *finalh = 0;
grib_handle *handle = 0;
grib_handle *finalh = 0;
grib_util_grid_spec spec={0,};
grib_util_packing_spec packing_spec={0,};
in = fopen(input_filename,"rb"); Assert(in);
handle = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err); Assert(handle);
handle = grib_handle_new_from_file(0, in, &err); Assert(handle);
CODES_CHECK(grib_get_string(handle, "packingType", gridType, &slen),0);
if (!STR_EQUAL(gridType, "grid_complex_spatial_differencing")) {
@ -281,13 +292,13 @@ static void test_grid_complex_spatial_differencing(int remove_local_def, int edi
}
out = fopen(output_filename,"wb"); Assert(out);
CODES_CHECK(codes_get_size(handle,"values",&inlen), 0);
CODES_CHECK(grib_get_size(handle,"values",&inlen), 0);
values = (double*)malloc(sizeof(double)*inlen);
CODES_CHECK(codes_get_double_array(handle, "values", values,&inlen), 0);
CODES_CHECK(grib_get_double_array(handle, "values", values,&inlen), 0);
CODES_CHECK(codes_get_double(handle, "max", &theMax),0);
CODES_CHECK(codes_get_double(handle, "min", &theMin),0);
CODES_CHECK(codes_get_double(handle, "average",&theAverage),0);
CODES_CHECK(grib_get_double(handle, "max", &theMax),0);
CODES_CHECK(grib_get_double(handle, "min", &theMin),0);
CODES_CHECK(grib_get_double(handle, "average",&theAverage),0);
printf("inlen=%lu \t max=%g \t min=%g \t avg=%g\n", inlen, theMax, theMin, theAverage);
spec.grid_type = GRIB_UTIL_GRID_SPEC_REGULAR_LL;
@ -315,7 +326,7 @@ static void test_grid_complex_spatial_differencing(int remove_local_def, int edi
packing_spec.deleteLocalDefinition = 1;
}
finalh = codes_grib_util_set_spec(
finalh = grib_util_set_spec(
handle,
&spec,
&packing_spec,
@ -327,12 +338,12 @@ static void test_grid_complex_spatial_differencing(int remove_local_def, int edi
Assert(err == 0);
/* Write out the message to the output file */
CODES_CHECK(codes_get_message(finalh, &buffer, &size),0);
CODES_CHECK(grib_get_message(finalh, &buffer, &size),0);
if(fwrite(buffer,1,size,out) != size) {
Assert(0);
}
codes_handle_delete(handle);
codes_handle_delete(finalh);
grib_handle_delete(handle);
grib_handle_delete(finalh);
fclose(in);
fclose(out);
}

View File

@ -14,7 +14,7 @@
# --------------------------------------------------
# Regular Lat/Lon Grid
# --------------------------------------------------
infile=../data/latlon.grib
infile=${data_dir}/latlon.grib # edition 1
outfile=out.grib_util_set_spec.grib
tempOut=temp.grib_util_set_spec.grib
grib_util_set_spec=${test_dir}/grib_util_set_spec
@ -42,7 +42,7 @@ res=`${tools_dir}/grib_get -p edition,section2Used $outfile`
[ "$res" = "2 0" ]
# GRIB2 input with local definition
infile=../data/regular_latlon_surface.grib2
infile=${data_dir}/regular_latlon_surface.grib2
$EXEC $grib_util_set_spec -r $infile $outfile > /dev/null
grib_check_key_equals $outfile section2Used 0
# GRIB2 input without local definition
@ -52,18 +52,26 @@ grib_check_key_equals $outfile section2Used 0
# Convert to edition2 and use JPEG for packing
if [ $HAVE_JPEG -eq 1 ]; then
infile=../data/latlon.grib
infile=${data_dir}/latlon.grib
$EXEC $grib_util_set_spec -e 2 -p grid_jpeg $infile $outfile > /dev/null
res=`${tools_dir}/grib_get -p edition,section2Used,packingType $outfile`
[ "$res" = "2 1 grid_jpeg" ]
fi
# Convert to edition2 and use CCSDS for packing
# CCSDS for packing and different editions
if [ $HAVE_AEC -eq 1 ]; then
infile=../data/latlon.grib
infile=${data_dir}/sample.grib2
$EXEC $grib_util_set_spec -p grid_ccsds $infile $outfile
grib_check_key_equals $outfile packingType grid_ccsds
infile=${data_dir}/latlon.grib #grib1
$EXEC $grib_util_set_spec -e 2 -p grid_ccsds $infile $outfile > /dev/null
res=`${tools_dir}/grib_get -p edition,section2Used,packingType $outfile`
[ "$res" = "2 1 grid_ccsds" ]
# If we don't convert, then should leave it as grid_simple (No CCSDS in grib1)
$EXEC $grib_util_set_spec -p grid_ccsds $infile $outfile
grib_check_key_equals $outfile packingType grid_simple
fi
# --------------------------------------------------
@ -72,7 +80,7 @@ fi
# The gaussian tests intentionally cause an error so need to stop it failing
unset ECCODES_FAIL_IF_LOG_MESSAGE
infile=../data/reduced_gaussian_model_level.grib2
infile=${data_dir}/reduced_gaussian_model_level.grib2
outfile=out.grib_util_set_spec.grib
rm -f $outfile
@ -84,7 +92,7 @@ $EXEC $grib_util_set_spec -p grid_second_order $infile $outfile
# Check output file. Values are scaled up by 1.1
grib_check_key_equals $outfile packingType grid_second_order
stats_new=`${tools_dir}/grib_get -F%.2f -p min,max $outfile`
[ "$stats_new" = "176.28 246.90" ]
[ "$stats_new" = "4.84 246.90" ]
${tools_dir}/grib_get_data $outfile > /dev/null
CHECK_TOOL="${tools_dir}/grib_check_gaussian_grid"
@ -93,15 +101,47 @@ if [ -x $CHECK_TOOL ]; then
fi
### Constant field N=32
###########################################
# ---------------------------
infile=$ECCODES_SAMPLES_PATH/reduced_gg_pl_32_grib2.tmpl
rm -f $outfile
$EXEC $grib_util_set_spec $infile $outfile
grib_check_key_equals $outfile "packingType,const" "grid_simple 1"
grib_check_key_equals $outfile "packingType,const" "grid_simple 0"
${tools_dir}/grib_get_data $outfile > /dev/null
# CCSDS input
# ---------------------------
if [ $HAVE_AEC -eq 1 ]; then
infile=${data_dir}/ccsds.grib2
$EXEC $grib_util_set_spec $infile $outfile
grib_check_key_equals $outfile packingType grid_ccsds
$EXEC $grib_util_set_spec -p grid_simple $infile $outfile
grib_check_key_equals $outfile packingType grid_simple
$EXEC $grib_util_set_spec -p grid_second_order $infile $outfile
grib_check_key_equals $outfile packingType grid_second_order
fi
# Second order input/output
# ---------------------------
${tools_dir}/grib_set -r -s packingType=grid_second_order ${data_dir}/sample.grib2 $tempOut
grib_check_key_equals $tempOut packingType grid_second_order
$EXEC $grib_util_set_spec $tempOut $outfile
grib_check_key_equals $outfile packingType grid_second_order
$EXEC $grib_util_set_spec -p grid_second_order ${data_dir}/simple.grib $outfile
grib_check_key_equals $outfile packingType grid_second_order
# Check DEBUG output
# ---------------------------
export ECCODES_DEBUG=-1
$EXEC $grib_util_set_spec ${data_dir}/sample.grib2 $outfile > $tempOut 2>&1
grep -q "ECCODES DEBUG grib_util:" $tempOut
### Clean up
rm -f $outfile $tempOut
rm -f error.data

View File

@ -10,7 +10,6 @@
#include "grib_api_internal.h"
#define STR_EQUAL(s1, s2) (strcmp((s1), (s2)) == 0)
#define NUMBER(x) (sizeof(x) / sizeof(x[0]))
int assertion_caught = 0;
@ -1404,10 +1403,10 @@ static void test_string_splitting()
if (!list) { Assert(!"List is NULL"); return; }
for (i = 0; list[i] != NULL; ++i) {} /* count how many tokens */
Assert(i == 4);
if (!list[0] || !STR_EQ(list[0], "Born")) Assert(0);
if (!list[1] || !STR_EQ(list[1], "To")) Assert(0);
if (!list[2] || !STR_EQ(list[2], "Be")) Assert(0);
if (!list[3] || !STR_EQ(list[3], "Wild")) Assert(0);
if (!list[0] || !STR_EQUAL(list[0], "Born")) Assert(0);
if (!list[1] || !STR_EQUAL(list[1], "To")) Assert(0);
if (!list[2] || !STR_EQUAL(list[2], "Be")) Assert(0);
if (!list[3] || !STR_EQUAL(list[3], "Wild")) Assert(0);
Assert(list[4] == NULL);
for (i = 0; list[i] != NULL; ++i) free(list[i]);
free(list);
@ -1417,8 +1416,8 @@ static void test_string_splitting()
if (!list) { Assert(0); return; }
for (i = 0; list[i] != NULL; ++i) {} /* count how many tokens */
Assert(i == 2);
if (!list[0] || !STR_EQ(list[0], "12345")) Assert(0);
if (!list[1] || !STR_EQ(list[1], "a gap")) Assert(0);
if (!list[0] || !STR_EQUAL(list[0], "12345")) Assert(0);
if (!list[1] || !STR_EQUAL(list[1], "a gap")) Assert(0);
Assert(list[2] == NULL);
for (i = 0; list[i] != NULL; ++i) free(list[i]);
free(list);
@ -1428,7 +1427,7 @@ static void test_string_splitting()
if (!list) { Assert(0); return; }
for (i = 0; list[i] != NULL; ++i) {} /* count how many tokens */
Assert(i == 1);
if (!list[0] || !STR_EQ(list[0], "Steppenwolf")) Assert(0);
if (!list[0] || !STR_EQUAL(list[0], "Steppenwolf")) Assert(0);
Assert(list[1] == NULL);
for (i = 0; list[i] != NULL; ++i) free(list[i]);
free(list);
@ -1654,11 +1653,45 @@ static void test_parse_keyval_string()
free( (void*)values3[0].name );
}
static void test_dates()
{
printf("Testing: dates...\n");
Assert( is_date_valid(1979,12, 1, 0,0,0) );
Assert( is_date_valid(1900, 1, 1, 0,0,0) );
Assert( is_date_valid(1964, 4, 6, 0,0,0) );
Assert( is_date_valid(2023, 3, 4, 0,0,0) );
Assert( is_date_valid(2023, 3, 4, 12,0,0) );
Assert( is_date_valid(2023, 3, 4, 0,10,0) );
Assert( is_date_valid(2023, 3, 4, 0,0,59) );
Assert( is_date_valid(0000, 3, 4, 0,0,0) );
Assert( is_date_valid(2020, 2, 29, 0,0,0) );//leap year
Assert( !is_date_valid( 10, -1, 1, 0,0,0) );// bad months
Assert( !is_date_valid(1900, 0, 1, 0,0,0) );
Assert( !is_date_valid(1900, 13, 1, 0,0,0) );
Assert( !is_date_valid(1900, 5, 0, 0,0,0) ); // bad days
Assert( !is_date_valid(2000, 5, 32, 0,0,0) );
Assert( !is_date_valid(2000, 5, -7, 0,0,0) );
Assert( !is_date_valid(2000, 5, 8, 99,0,0) );//bad hours
Assert( !is_date_valid(2000, 5, 9, -1,0,0) );
Assert( !is_date_valid(2000, 5, 8, 0, 61,0) );//bad mins
Assert( !is_date_valid(2000, 5, 9, 0,-1, 0) );
Assert( !is_date_valid(2000, 5, 8, 0, 1, -1) );//bad secs
Assert( !is_date_valid(2000, 5, 9, 0, 1, 60) );
Assert( !is_date_valid(2023, 2, 29, 0,0,0) );//Feb
}
int main(int argc, char** argv)
{
printf("Doing unit tests. ecCodes version = %ld\n", grib_get_api_version());
test_dates();
test_logging_proc();
test_grib_binary_search();
test_parse_keyval_string();

View File

@ -22,7 +22,6 @@
#include "grib_api_internal.h"
#define STR_EQUAL(s1, s2) (strcmp((s1), (s2)) == 0)
int exit_on_error = 1; /* By default exit if any check fails */
int verbose = 0; /* By default quiet unless errors */

View File

@ -4011,13 +4011,14 @@ int grib_tool_init(grib_runtime_options* options)
/* Option -S: Split according to keys */
if (grib_options_on("S:")) {
char* lasts = NULL;
list = grib_options_get_option("S:");
p = strtok(list, ",");
p = strtok_r(list, ",", &lasts);
set_value(user_r, "split", p);
p = strtok(NULL, ",");
p = strtok_r(NULL, ",", &lasts);
while (p != NULL) {
add_value(user_r, "split", p);
p = strtok(NULL, ",");
p = strtok_r(NULL, ",", &lasts);
}
}
else {
@ -4027,13 +4028,14 @@ int grib_tool_init(grib_runtime_options* options)
/* Option -I: Ignore keys */
if (grib_options_on("I:")) {
char* lasts = NULL;
list = grib_options_get_option("I:");
p = strtok(list, ",");
p = strtok_r(list, ",", &lasts);
set_value(user_r, "ignore", p);
p = strtok(NULL, ",");
p = strtok_r(NULL, ",", &lasts);
while (p != NULL) {
add_value(user_r, "ignore", p);
p = strtok(NULL, ",");
p = strtok_r(NULL, ",", &lasts);
}
}
else {
@ -4373,7 +4375,6 @@ int grib_no_handle_action(grib_runtime_options* options, int err)
#else
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv)
{
printf("\n");

View File

@ -799,7 +799,7 @@ static void grib_tools_set_print_keys(grib_runtime_options* options, grib_handle
}
}
static int to_skip(grib_handle* h, grib_values* v, int* err)
static int to_skip(grib_runtime_options* options, grib_handle* h, grib_values* v, int* err)
{
double dvalue = 0;
int ret = 0;
@ -808,6 +808,13 @@ static int to_skip(grib_handle* h, grib_values* v, int* err)
size_t len = MAX_STRING_LEN;
*err = 0;
Assert(options->constraints_count > 0);
if (strcmp(v->name, "count")==0 && v->long_value < 1) {
fprintf(dump_file, "ERROR: Invalid value for key '%s' (must be an integer greater than 0)\n", v->name);
exit(1);
}
switch (v->type) {
case GRIB_TYPE_STRING:
*err = grib_get_string(h, v->name, value, &len);
@ -853,7 +860,7 @@ void grib_skip_check(grib_runtime_options* options, grib_handle* h)
if (v->equal) {
options->skip = 1;
while (v) {
if (!to_skip(h, v, &ret)) {
if (!to_skip(options, h, v, &ret)) {
if (!strcmp(v->name, "count") && !v->next) {
/* We have count=XX and nothing after that so we can
* skip every other message after it
@ -874,7 +881,7 @@ void grib_skip_check(grib_runtime_options* options, grib_handle* h)
else {
options->skip = 0;
while (v) {
if (to_skip(h, v, &ret)) {
if (to_skip(options, h, v, &ret)) {
options->skip = 1;
break;
}

View File

@ -1,2 +0,0 @@
[flake8]
ignore = F403