mirror of https://github.com/ecmwf/eccodes.git
Replace Asserts with proper error messages and exit codes
This commit is contained in:
parent
989b1a01f3
commit
d7bf7f9fa5
|
@ -4,7 +4,7 @@
|
|||
## created: 6 Oct 2011
|
||||
## modified: 13 May 2013
|
||||
##
|
||||
# CODE TABLE 3 Fixed levels or layers for wich the data are included
|
||||
# CODE TABLE 3 Fixed levels or layers for which the data are included
|
||||
0 0 Reserved
|
||||
1 surf Surface (of the Earth, which includes sea surface)
|
||||
2 bcld Cloud base level
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
!> \b Examples: \ref grib_index.f90 "grib_index.f90"
|
||||
!>
|
||||
!> @param indexid id of an index created from a file. The index must have been created with the key in argument.
|
||||
!> @param key key for wich the values are returned
|
||||
!> @param key key for which the values are returned
|
||||
!> @param values array of values. The array must be allocated before entering this function and its size must be enough to contain all the values.
|
||||
!> @param status CODES_SUCCESS if OK, integer value on error
|
||||
interface codes_index_get
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
!> \b Examples: \ref grib_index.f90 "grib_index.f90"
|
||||
!>
|
||||
!> @param indexid id of an index created from a file. The index must have been created with the key in argument.
|
||||
!> @param key key for wich the values are returned
|
||||
!> @param key key for which the values are returned
|
||||
!> @param values array of values. The array must be allocated before entering this function and its size must be enough to contain all the values.
|
||||
!> @param status CODES_SUCCESS if OK, integer value on error
|
||||
interface codes_index_get
|
||||
|
|
|
@ -121,7 +121,7 @@
|
|||
!> \b Examples: \ref grib_index.f90 "grib_index.f90"
|
||||
!>
|
||||
!> @param indexid id of an index created from a file. The index must have been created with the key in argument.
|
||||
!> @param key key for wich the values are returned
|
||||
!> @param key key for which the values are returned
|
||||
!> @param values array of values. The array must be allocated before entering this function and its size must be enough to contain all the values.
|
||||
!> @param status CODES_SUCCESS if OK, integer value on error
|
||||
subroutine codes_index_get_int(indexid, key, values, status)
|
||||
|
@ -143,7 +143,7 @@
|
|||
!> \b Examples: \ref grib_index.f90 "grib_index.f90"
|
||||
!>
|
||||
!> @param indexid id of an index created from a file. The index must have been created with the key in argument.
|
||||
!> @param key key for wich the values are returned
|
||||
!> @param key key for which the values are returned
|
||||
!> @param values array of values. The array must be allocated before entering this function and its size must be enough to contain all the values.
|
||||
!> @param status CODES_SUCCESS if OK, integer value on error
|
||||
subroutine codes_index_get_long(indexid, key, values, status)
|
||||
|
@ -165,7 +165,7 @@
|
|||
!> \b Examples: \ref grib_index.f90 "grib_index.f90"
|
||||
!>
|
||||
!> @param indexid id of an index created from a file. The index must have been created with the key in argument.
|
||||
!> @param key key for wich the values are returned
|
||||
!> @param key key for which the values are returned
|
||||
!> @param values array of values. The array must be allocated before entering this function and its size must be enough to contain all the values.
|
||||
!> @param status CODES_SUCCESS if OK, integer value on error
|
||||
subroutine codes_index_get_real8(indexid, key, values, status)
|
||||
|
@ -189,7 +189,7 @@
|
|||
!> \b Examples: \ref grib_index.f90 "grib_index.f90"
|
||||
!>
|
||||
!> @param indexid id of an index created from a file. The index must have been created with the key in argument.
|
||||
!> @param key key for wich the values are returned
|
||||
!> @param key key for which the values are returned
|
||||
!> @param values array of values. The array must be allocated before entering this function and its size must be enough to contain all the values.
|
||||
!> @param status CODES_SUCCESS if OK, integer value on error
|
||||
subroutine codes_index_get_string(indexid, key, values, status)
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
!> \b Examples: \ref grib_index.f90 "grib_index.f90"
|
||||
!>
|
||||
!> @param indexid id of an index created from a file. The index must have been created with the key in argument.
|
||||
!> @param key key for wich the values are returned
|
||||
!> @param key key for which the values are returned
|
||||
!> @param values array of values. The array must be allocated before entering this function and its size must be enough to contain all the values.
|
||||
!> @param status GRIB_SUCCESS if OK, integer value on error
|
||||
interface grib_index_get
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
!> \b Examples: \ref grib_index.f90 "grib_index.f90"
|
||||
!>
|
||||
!> @param indexid id of an index created from a file. The index must have been created with the key in argument.
|
||||
!> @param key key for wich the values are returned
|
||||
!> @param key key for which the values are returned
|
||||
!> @param values array of values. The array must be allocated before entering this function and its size must be enough to contain all the values.
|
||||
!> @param status GRIB_SUCCESS if OK, integer value on error
|
||||
interface grib_index_get
|
||||
|
|
|
@ -154,7 +154,7 @@
|
|||
!> \b Examples: \ref grib_index.f90 "grib_index.f90"
|
||||
!>
|
||||
!> @param indexid ID of an index created from a file. The index must have been created with the key in argument.
|
||||
!> @param key key for wich the values are returned
|
||||
!> @param key key for which the values are returned
|
||||
!> @param values array of values. The array must be allocated before entering this function and its size must be enough to contain all the values.
|
||||
!> @param status GRIB_SUCCESS if OK, integer value on error
|
||||
subroutine grib_index_get_int(indexid, key, values, status)
|
||||
|
@ -184,7 +184,7 @@
|
|||
!> \b Examples: \ref grib_index.f90 "grib_index.f90"
|
||||
!>
|
||||
!> @param indexid ID of an index created from a file. The index must have been created with the key in argument.
|
||||
!> @param key key for wich the values are returned
|
||||
!> @param key key for which the values are returned
|
||||
!> @param values array of values. The array must be allocated before entering this function and its size must be enough to contain all the values.
|
||||
!> @param status GRIB_SUCCESS if OK, integer value on error
|
||||
subroutine grib_index_get_long(indexid, key, values, status)
|
||||
|
@ -214,7 +214,7 @@
|
|||
!> \b Examples: \ref grib_index.f90 "grib_index.f90"
|
||||
!>
|
||||
!> @param indexid id of an index created from a file. The index must have been created with the key in argument.
|
||||
!> @param key key for wich the values are returned
|
||||
!> @param key key for which the values are returned
|
||||
!> @param values array of values. The array must be allocated before entering this function and its size must be enough to contain all the values.
|
||||
!> @param status GRIB_SUCCESS if OK, integer value on error
|
||||
subroutine grib_index_get_real8(indexid, key, values, status)
|
||||
|
@ -246,7 +246,7 @@
|
|||
!> \b Examples: \ref grib_index.f90 "grib_index.f90"
|
||||
!>
|
||||
!> @param indexid id of an index created from a file. The index must have been created with the key in argument.
|
||||
!> @param key key for wich the values are returned
|
||||
!> @param key key for which the values are returned
|
||||
!> @param values array of values. The array must be allocated before entering this function and its size must be enough to contain all the values.
|
||||
!> @param status GRIB_SUCCESS if OK, integer value on error
|
||||
subroutine grib_index_get_string(indexid, key, values, status)
|
||||
|
|
|
@ -168,13 +168,11 @@ static void init(grib_accessor* a, const long v, grib_arguments* args)
|
|||
static int value_count(grib_accessor* a, long* count)
|
||||
{
|
||||
grib_accessor_data_complex_packing* self = (grib_accessor_data_complex_packing*)a;
|
||||
int ret = 0;
|
||||
grib_handle* gh = grib_handle_of_accessor(a);
|
||||
|
||||
int ret = 0;
|
||||
grib_handle* gh = grib_handle_of_accessor(a);
|
||||
long pen_j = 0;
|
||||
long pen_k = 0;
|
||||
long pen_m = 0;
|
||||
|
||||
*count = 0;
|
||||
|
||||
if (a->length == 0)
|
||||
|
@ -188,15 +186,16 @@ static int value_count(grib_accessor* a, long* count)
|
|||
return ret;
|
||||
|
||||
if (pen_j != pen_k || pen_j != pen_m) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "pen_j=%ld, pen_k=%ld, pen_m=%ld\n", pen_j, pen_k, pen_m);
|
||||
Assert((pen_j == pen_k) && (pen_j == pen_m));
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "Invalid pentagonal resolution parameters");
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "pen_j=%ld, pen_k=%ld, pen_m=%ld", pen_j, pen_k, pen_m);
|
||||
return GRIB_DECODING_ERROR;
|
||||
}
|
||||
*count = (pen_j + 1) * (pen_j + 2);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static double calculate_pfactor(grib_context* ctx, const double* spectralField, long fieldTruncation, long subsetTruncation)
|
||||
static double calculate_pfactor(const grib_context* ctx, const double* spectralField, long fieldTruncation, long subsetTruncation)
|
||||
{
|
||||
/*long n_vals = ((fieldTruncation+1)*(fieldTruncation+2));*/
|
||||
long loop, index, m, n = 0;
|
||||
|
@ -416,10 +415,10 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
|
|||
return GRIB_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
Assert(sub_j == sub_k);
|
||||
Assert(sub_j == sub_m);
|
||||
Assert(pen_j == pen_k);
|
||||
Assert(pen_j == pen_m);
|
||||
if (sub_j != sub_k || sub_j != sub_m || pen_j != pen_k || pen_j != pen_m) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "%s: Invalid pentagonal resolution parameters", cclass_name);
|
||||
return GRIB_ENCODING_ERROR;
|
||||
}
|
||||
|
||||
n_vals = (pen_j + 1) * (pen_j + 2);
|
||||
|
||||
|
@ -790,10 +789,10 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
|
|||
return GRIB_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
Assert(sub_j == sub_k);
|
||||
Assert(sub_j == sub_m);
|
||||
Assert(pen_j == pen_k);
|
||||
Assert(pen_j == pen_m);
|
||||
if (sub_j != sub_k || sub_j != sub_m || pen_j != pen_k || pen_j != pen_m) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "%s: Invalid pentagonal resolution parameters", cclass_name);
|
||||
return GRIB_DECODING_ERROR;
|
||||
}
|
||||
|
||||
buf = (unsigned char*)gh->buffer->data;
|
||||
|
||||
|
|
|
@ -164,8 +164,9 @@ static void init(grib_accessor* a, const long v, grib_arguments* args)
|
|||
static int value_count(grib_accessor* a, long* count)
|
||||
{
|
||||
grib_accessor_data_sh_packed* self = (grib_accessor_data_sh_packed*)a;
|
||||
grib_handle* hand = grib_handle_of_accessor(a);
|
||||
int ret = 0;
|
||||
grib_handle* hand = grib_handle_of_accessor(a);
|
||||
int ret = 0;
|
||||
const char* cclass_name = a->cclass->name;
|
||||
|
||||
long sub_j = 0;
|
||||
long sub_k = 0;
|
||||
|
@ -189,8 +190,9 @@ static int value_count(grib_accessor* a, long* count)
|
|||
return ret;
|
||||
|
||||
if (pen_j != pen_k || pen_j != pen_m) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "pen_j=%ld, pen_k=%ld, pen_m=%ld\n", pen_j, pen_k, pen_m);
|
||||
Assert((pen_j == pen_k) && (pen_j == pen_m));
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "%s: pen_j=%ld, pen_k=%ld, pen_m=%ld\n",
|
||||
cclass_name, pen_j, pen_k, pen_m);
|
||||
return GRIB_DECODING_ERROR;
|
||||
}
|
||||
*count = (pen_j + 1) * (pen_j + 2) - (sub_j + 1) * (sub_j + 2);
|
||||
return ret;
|
||||
|
@ -200,20 +202,13 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
|
|||
{
|
||||
grib_accessor_data_sh_packed* self = (grib_accessor_data_sh_packed*)a;
|
||||
|
||||
size_t i = 0;
|
||||
int ret = GRIB_SUCCESS;
|
||||
long hcount = 0;
|
||||
long lcount = 0;
|
||||
long hpos = 0;
|
||||
long lup = 0;
|
||||
long mmax = 0;
|
||||
long n_vals = 0;
|
||||
size_t i = 0;
|
||||
int ret = GRIB_SUCCESS;
|
||||
long hcount = 0, lcount = 0, hpos = 0, lup = 0, mmax = 0, n_vals = 0;
|
||||
double* scals = NULL;
|
||||
/* double *pscals=NULL; */
|
||||
|
||||
double s = 0;
|
||||
double d = 0;
|
||||
double laplacianOperator = 0;
|
||||
double s = 0, d = 0, laplacianOperator = 0;
|
||||
unsigned char* buf = NULL;
|
||||
unsigned char* hres = NULL;
|
||||
unsigned char* lres = NULL;
|
||||
|
@ -223,22 +218,16 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
|
|||
long maxv = 0;
|
||||
long GRIBEX_sh_bug_present = 0;
|
||||
long ieee_floats = 0;
|
||||
|
||||
long offsetdata = 0;
|
||||
long bits_per_value = 0;
|
||||
double reference_value = 0;
|
||||
long binary_scale_factor = 0;
|
||||
long decimal_scale_factor = 0;
|
||||
|
||||
long sub_j = 0;
|
||||
long sub_k = 0;
|
||||
long sub_m = 0;
|
||||
long pen_j = 0;
|
||||
long pen_k = 0;
|
||||
long pen_m = 0;
|
||||
long sub_j = 0, sub_k = 0, sub_m = 0, pen_j = 0, pen_k = 0, pen_m = 0;
|
||||
|
||||
double operat = 0;
|
||||
int bytes;
|
||||
int bytes = 0;
|
||||
int err = 0;
|
||||
|
||||
decode_float_proc decode_float = NULL;
|
||||
|
@ -326,7 +315,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
|
|||
d = codes_power<double>(-decimal_scale_factor, 10);
|
||||
|
||||
scals = (double*)grib_context_malloc(a->context, maxv * sizeof(double));
|
||||
Assert(scals);
|
||||
if(!scals) return GRIB_OUT_OF_MEMORY;
|
||||
|
||||
scals[0] = 0;
|
||||
for (i = 1; i < maxv; i++) {
|
||||
|
|
Loading…
Reference in New Issue