Merge branch 'develop' into feature/ECC-1466-GRIB2Defs

This commit is contained in:
Shahram Najm 2022-11-16 17:01:14 +00:00
commit c48ef82a31
5 changed files with 315 additions and 33 deletions

View File

@ -532,3 +532,24 @@ void codes_context_set_samples_path(grib_context* c, const char* path)
{
grib_context_set_samples_path(c, path);
}
void codes_context_set_memory_proc(grib_context* c, grib_malloc_proc p_malloc, grib_free_proc p_free, grib_realloc_proc p_realloc)
{
grib_context_set_memory_proc(c, p_malloc, p_free, p_realloc);
}
void codes_context_set_persistent_memory_proc(grib_context* c, grib_malloc_proc p_malloc, grib_free_proc p_free)
{
grib_context_set_persistent_memory_proc(c, p_malloc, p_free);
}
void codes_context_set_buffer_memory_proc(grib_context* c, grib_malloc_proc p_malloc, grib_free_proc p_free, grib_realloc_proc p_realloc)
{
grib_context_set_buffer_memory_proc(c, p_malloc, p_free, p_realloc);
}
void codes_context_set_print_proc(grib_context* c, grib_print_proc p_print)
{
grib_context_set_print_proc(c, p_print);
}
void codes_context_set_logging_proc(grib_context* c, grib_log_proc p_log)
{
grib_context_set_logging_proc(c, p_log);
}

View File

@ -990,22 +990,107 @@ void codes_dump_action_tree(codes_context* c, FILE* f);
*/
/*! @{ */
/* TODO: function pointers
grib_malloc_proc
grib_realloc_proc
grib_log_proc
grib_print_proc
grib_data_read_proc
grib_data_write_proc
grib_data_tell_proc
grib_data_seek_proc
grib_data_eof_proc
/**
* ecCodes free procedure, format of a procedure referenced in the context that is used to free memory
*
* @param c : the context where the memory freeing will apply
* @param data : pointer to the data to be freed
* must match @see codes_malloc_proc
*/
typedef void (*codes_free_proc)(const codes_context* c, void* data);
/**
* ecCodes malloc procedure, format of a procedure referenced in the context that is used to allocate memory
* @param c : the context where the memory allocation will apply
* @param length : length to be allocated in number of bytes
* @return a pointer to the allocated memory, NULL if no memory can be allocated
* must match @see codes_free_proc
*/
typedef void* (*codes_malloc_proc)(const codes_context* c, size_t length);
/**
* ecCodes realloc procedure, format of a procedure referenced in the context that is used to reallocate memory
* @param c : the context where the memory allocation will apply
* @param data : pointer to the data to be reallocated
* @param length : length to be allocated in number of bytes
* @return a pointer to the allocated memory
*/
typedef void* (*codes_realloc_proc)(const codes_context* c, void* data, size_t length);
/**
* ecCodes log procedure, format of a procedure referenced in the context that is used to log internal messages
*
* @param c : the context where the logging will apply
* @param level : the log level, as defined in log modes
* @param mesg : the message to be logged
*/
typedef void (*codes_log_proc)(const codes_context* c, int level, const char* mesg);
/**
* ecCodes print procedure, format of a procedure referenced in the context that is used to print external messages
*
* @param c : the context where the logging will apply
* @param descriptor : the structure to be printed on, must match the implementation
* @param mesg : the message to be printed
*/
typedef void (*codes_print_proc)(const codes_context* c, void* descriptor, const char* mesg);
/**
* ecCodes data read procedure, format of a procedure referenced in the context that is used to read from a stream in a resource
*
* @param c : the context where the read will apply
* @param ptr : the resource
* @param size : size to read
* @param stream : the stream
* @return size read
*/
typedef size_t (*codes_data_read_proc)(const codes_context* c, void* ptr, size_t size, void* stream);
/**
* ecCodes data write procedure, format of a procedure referenced in the context that is used to write to a stream from a resource
*
* @param c : the context where the write will apply
* @param ptr : the resource
* @param size : size to read
* @param stream : the stream
* @return size written
*/
typedef size_t (*codes_data_write_proc)(const codes_context* c, const void* ptr, size_t size, void* stream);
/**
* ecCodes data tell procedure, format of a procedure referenced in the context that is used to tell the current position in a stream
*
* @param c : the context where the tell will apply
* @param stream : the stream
* @return the position in the stream
*/
typedef off_t (*codes_data_tell_proc)(const codes_context* c, void* stream);
/**
* ecCodes data seek procedure, format of a procedure referenced in the context that is used to seek the current position in a stream
*
* @param c : the context where the tell will apply
* @param offset : the offset to seek to
* @param whence : If whence is set to SEEK_SET, SEEK_CUR, or SEEK_END,
the offset is relative to the start of the file, the current position indicator, or end-of-file, respectively.
* @param stream : the stream
* @return 0 if OK, integer value on error
*/
typedef off_t (*codes_data_seek_proc)(const codes_context* c, off_t offset, int whence, void* stream);
/**
* ecCodes data eof procedure, format of a procedure referenced in the context that is used to test end of file
*
* @param c : the context where the tell will apply
* @param stream : the stream
* @return the position in the stream
*/
typedef int (*codes_data_eof_proc)(const codes_context* c, void* stream);
/**
* Get the static default context
*
* @return the default context, NULL it the context is not available
* @return the default context, NULL it the context is not available
*/
codes_context* codes_context_get_default(void);
@ -1076,6 +1161,54 @@ void codes_context_set_definitions_path(codes_context* c, const char* path);
*/
void codes_context_set_samples_path(codes_context* c, const char* path);
/**
* Sets memory procedures of the context
*
* @param c : the context to be modified
* @param p_malloc : the memory allocation procedure to be set @see codes_malloc_proc
* @param p_free : the memory freeing procedure to be set @see codes_free_proc
* @param p_realloc : the memory reallocation procedure to be set @see codes_realloc_proc
*/
void codes_context_set_memory_proc(codes_context* c, codes_malloc_proc p_malloc,
codes_free_proc p_free, codes_realloc_proc p_realloc);
/**
* Sets memory procedures of the context for persistent data
*
* @param c : the context to be modified
* @param griballoc : the memory allocation procedure to be set @see codes_malloc_proc
* @param gribfree : the memory freeing procedure to be set @see codes_free_proc
*/
void codes_context_set_persistent_memory_proc(codes_context* c, codes_malloc_proc p_malloc,
codes_free_proc p_free);
/**
* Sets memory procedures of the context for large buffers
*
* @param c : the context to be modified
* @param p_malloc : the memory allocation procedure to be set @see codes_malloc_proc
* @param p_free : the memory freeing procedure to be set @see codes_free_proc
* @param p_free : the memory reallocation procedure to be set @see codes_realloc_proc
*/
void codes_context_set_buffer_memory_proc(codes_context* c, codes_malloc_proc p_malloc,
codes_free_proc p_free, codes_realloc_proc p_realloc);
/**
* Sets the context printing procedure used for user interaction
*
* @param c : the context to be modified
* @param p_print : the printing procedure to be set @see codes_print_proc
*/
void codes_context_set_print_proc(codes_context* c, codes_print_proc p_print);
/**
* Sets the context logging procedure used for system (warning, errors, infos ...) messages
*
* @param c : the context to be modified
* @param p_log : the logging procedure to be set @see codes_log_proc
*/
void codes_context_set_logging_proc(codes_context* c, codes_log_proc p_log);
/**
* Turn on support for multi-fields in single GRIB messages
*
@ -1303,7 +1436,7 @@ int codes_bufr_header_get_string(codes_bufr_header* bh, const char* key, char* v
* strict_mode = If 1 means fail if any message is invalid.
* returns 0 if OK, integer value on error.
*/
int codes_extract_offsets_malloc(grib_context* c, const char* filename, ProductKind product, off_t** offsets, int* num_messages, int strict_mode);
int codes_extract_offsets_malloc(codes_context* c, const char* filename, ProductKind product, off_t** offsets, int* num_messages, int strict_mode);
/* --------------------------------------- */
#ifdef __cplusplus

View File

@ -1005,7 +1005,7 @@ void grib_dump_action_tree(grib_context* c, FILE* f);
*/
/*! @{ */
/**
* Grib free procedure, format of a procedure referenced in the context that is used to free memory
* free procedure, format of a procedure referenced in the context that is used to free memory
*
* @param c : the context where the memory freeing will apply
* @param data : pointer to the data to be freed
@ -1014,7 +1014,7 @@ void grib_dump_action_tree(grib_context* c, FILE* f);
typedef void (*grib_free_proc)(const grib_context* c, void* data);
/**
* Grib malloc procedure, format of a procedure referenced in the context that is used to allocate memory
* malloc procedure, format of a procedure referenced in the context that is used to allocate memory
* @param c : the context where the memory allocation will apply
* @param length : length to be allocated in number of bytes
* @return a pointer to the allocated memory, NULL if no memory can be allocated
@ -1023,7 +1023,7 @@ typedef void (*grib_free_proc)(const grib_context* c, void* data);
typedef void* (*grib_malloc_proc)(const grib_context* c, size_t length);
/**
* Grib realloc procedure, format of a procedure referenced in the context that is used to reallocate memory
* realloc procedure, format of a procedure referenced in the context that is used to reallocate memory
* @param c : the context where the memory allocation will apply
* @param data : pointer to the data to be reallocated
* @param length : length to be allocated in number of bytes
@ -1032,7 +1032,7 @@ typedef void* (*grib_malloc_proc)(const grib_context* c, size_t length);
typedef void* (*grib_realloc_proc)(const grib_context* c, void* data, size_t length);
/**
* Grib loc proc, format of a procedure referenced in the context that is used to log internal messages
* log procedure, format of a procedure referenced in the context that is used to log internal messages
*
* @param c : the context where the logging will apply
* @param level : the log level, as defined in log modes
@ -1041,7 +1041,7 @@ typedef void* (*grib_realloc_proc)(const grib_context* c, void* data, size_t len
typedef void (*grib_log_proc)(const grib_context* c, int level, const char* mesg);
/**
* Grib print proc, format of a procedure referenced in the context that is used to print external messages
* print procedure, format of a procedure referenced in the context that is used to print external messages
*
* @param c : the context where the logging will apply
* @param descriptor : the structure to be printed on, must match the implementation
@ -1051,29 +1051,29 @@ typedef void (*grib_print_proc)(const grib_context* c, void* descriptor, const c
/**
* Grib data read proc, format of a procedure referenced in the context that is used to read from a stream in a resource
* data read procedure, format of a procedure referenced in the context that is used to read from a stream in a resource
*
* @param c : the context where the read will apply
* @param c : the context where the read will apply
* @param ptr : the resource
* @param size : size to read
* @param size : size to read
* @param stream : the stream
* @return size read
*/
typedef size_t (*grib_data_read_proc)(const grib_context* c, void* ptr, size_t size, void* stream);
/**
* Grib data read write, format of a procedure referenced in the context that is used to write to a stream from a resource
* data write procedure, format of a procedure referenced in the context that is used to write to a stream from a resource
*
* @param c : the context where the write will apply
* @param c : the context where the write will apply
* @param ptr : the resource
* @param size : size to read
* @param size : size to read
* @param stream : the stream
* @return size written
*/
typedef size_t (*grib_data_write_proc)(const grib_context* c, const void* ptr, size_t size, void* stream);
/**
* Grib data tell, format of a procedure referenced in the context that is used to tell the current position in a stream
* data tell procedure, format of a procedure referenced in the context that is used to tell the current position in a stream
*
* @param c : the context where the tell will apply
* @param stream : the stream
@ -1082,20 +1082,19 @@ typedef size_t (*grib_data_write_proc)(const grib_context* c, const void* ptr, s
typedef off_t (*grib_data_tell_proc)(const grib_context* c, void* stream);
/**
* Grib data seek, format of a procedure referenced in the context that is used to seek the current position in a stream
* data seek procedure, format of a procedure referenced in the context that is used to seek the current position in a stream
*
* @param c : the context where the tell will apply
* @param offset : the offset to seek to
* @param whence : If whence is set to SEEK_SET, SEEK_CUR, or SEEK_END,
the offset is relative to the start of the file,
the current position indicator, or end-of-file, respectively.
* @param stream : the stream
* @return 0 if OK, integer value on error
* @param c : the context where the tell will apply
* @param offset : the offset to seek to
* @param whence : If whence is set to SEEK_SET, SEEK_CUR, or SEEK_END,
the offset is relative to the start of the file, the current position indicator, or end-of-file, respectively.
* @param stream : the stream
* @return 0 if OK, integer value on error
*/
typedef off_t (*grib_data_seek_proc)(const grib_context* c, off_t offset, int whence, void* stream);
/**
* Grib data eof, format of a procedure referenced in the context that is used to test end of file
* data eof procedure, format of a procedure referenced in the context that is used to test end of file
*
* @param c : the context where the tell will apply
* @param stream : the stream

View File

@ -197,6 +197,7 @@ if( HAVE_BUILD_TOOLS )
bufr_ecc-887
bufr_ecc-1187
bufr_ecc-1305
bufr_ecc-1476
grib_ecc-490
grib_ecc-756
grib_ecc-806

128
tests/bufr_ecc-1476.sh Executable file
View File

@ -0,0 +1,128 @@
#!/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="bufr_ecc-1476_test"
tempFilt=temp.$label.filt
tempLog=temp.$label.log
set +u
if test "x$ECCODES_TEST_WITH_VALGRIND" = "x"; then
echo "Environment variable ECCODES_TEST_WITH_VALGRIND not defined. Test disabled"
exit 0
fi
set -u
# The presence of ECCODES_TEST_WITH_VALGRIND environment variable redefines
# tools_dir so we reset it to its original
tools_dir=$build_dir/bin
files="
aaen_55.bufr
aben_55.bufr
ahws_139.bufr
airs_57.bufr
alws_139.bufr
amsa_55.bufr
amsb_55.bufr
amse_55.bufr
amsu_55.bufr
amv2_87.bufr
amv3_87.bufr
asbh_139.bufr
asbl_139.bufr
asca_139.bufr
asch_139.bufr
ascs_139.bufr
aseh_139.bufr
asel_139.bufr
ashs_139.bufr
atap_55.bufr
ateu_155.bufr
atms_201.bufr
atov_55.bufr
avhm_87.bufr
avhn_87.bufr
avhr_58.bufr
b002_95.bufr
b002_96.bufr
b003_56.bufr
b005_87.bufr
b005_89.bufr
b006_96.bufr
cmwi_87.bufr
cmwn_87.bufr
cori_156.bufr
crit_202.bufr
csrh_189.bufr
ecc738.msg2.bufr
emsg_189.bufr
emsg_87.bufr
eumetsat_iasi_co.bufr
eum_iasi_twt.bufr
euwv_87.bufr
fy3a_154.bufr
fy3b_154.bufr
g2to_206.bufr
go15_87.bufr
goee_87.bufr
goes_87.bufr
goga_89.bufr
hirb_55.bufr
hirs_55.bufr
iasi_241.bufr
imssnow.bufr
itwt_233.bufr
jaso_214.bufr
maer_207.bufr
mhen_55.bufr
mhsa_55.bufr
mhsb_55.bufr
mhse_55.bufr
mloz_206.bufr
modi_87.bufr
modw_87.bufr
monw_87.bufr
new.bufr
nomi_206.bufr
ocea_21.bufr
pilo_91.bufr
profiler_european.bufr
rada_250.bufr
rado_250.bufr
s4kn_165.bufr
sb19_206.bufr
sbu8_206.bufr
smin_49.bufr
smis_49.bufr
smiu_49.bufr
smos_203.bufr
sn4k_165.bufr
soil_7.bufr
ssbt_127.bufr
stuk_7.bufr
syno_1.bufr
syno_3.bufr
syno_4.bufr
temp_101.bufr
temp-land-with-substituted-values.bufr
tmr7_129.bufr
"
VALGRIND_OPTIONS="--error-exitcode=1 --leak-check=full --log-file=$tempLog"
for f in $files; do
bf=${data_dir}/bufr/$f
${tools_dir}/bufr_dump -Efilter $bf > $tempFilt #>& /dev/null
valgrind $VALGRIND_OPTIONS ${tools_dir}/codes_bufr_filter $tempFilt $bf >/dev/null
rm -f $tempFilt
done
rm -f $tempLog $tempFilt