mirror of https://github.com/ecmwf/eccodes.git
Examples: cpplint warning [runtime/threadsafe_fn]
This commit is contained in:
parent
8ac436a104
commit
168537f503
|
@ -22,6 +22,7 @@ int main()
|
|||
int i = 0;
|
||||
codes_handle* h = NULL;
|
||||
const char* filename = "bigfile.grib";
|
||||
unsigned int seed = time(NULL);
|
||||
|
||||
numbytes = ni * nj * sizeof(double);
|
||||
values = (double*)malloc(numbytes);
|
||||
|
@ -31,7 +32,7 @@ int main()
|
|||
}
|
||||
|
||||
for (i = 0; i < ni * nj; i++) {
|
||||
double r = rand() * 1.0 / RAND_MAX;
|
||||
double r = rand_r(&seed) * 1.0 / RAND_MAX;
|
||||
values[i] = r;
|
||||
}
|
||||
|
||||
|
@ -65,7 +66,6 @@ int main()
|
|||
CODES_CHECK(codes_set_double_array(h, "values", values, ni * nj), 0);
|
||||
|
||||
codes_write_message(h, filename, "w");
|
||||
/*printf("Wrote file %s\n", filename);*/
|
||||
|
||||
codes_handle_delete(h);
|
||||
free(values);
|
||||
|
|
|
@ -9,10 +9,13 @@
|
|||
|
||||
. ./include.ctest.sh
|
||||
|
||||
# The executable should produce a GRIB1 file
|
||||
# The executable will produce a GRIB1 file called "bigfile.grib"
|
||||
output=bigfile.grib
|
||||
${examples_dir}/c_large_grib1
|
||||
|
||||
# Make sure the newly created file can be listed OK
|
||||
output=bigfile.grib
|
||||
${tools_dir}/grib_ls $output > /dev/null
|
||||
${tools_dir}/grib_ls -p numberOfDataPoints,numberOfCodedValues,numberOfMissing $output
|
||||
num=$(${tools_dir}/grib_get -p numberOfDataPoints $output)
|
||||
[ $num = 8294400 ]
|
||||
|
||||
rm -f $output
|
||||
|
|
|
@ -165,6 +165,14 @@ static void dump(grib_accessor* a, grib_dumper* dumper)
|
|||
grib_dump_long(dumper, a, NULL);
|
||||
}
|
||||
|
||||
static bool is_tigge(grib_handle* h)
|
||||
{
|
||||
long productionStatus = 0;
|
||||
int err = grib_get_long(h, "productionStatusOfProcessedData", &productionStatus);
|
||||
if (err) return false;
|
||||
return (productionStatus == 4 || productionStatus == 5);
|
||||
}
|
||||
|
||||
static int unpack_double(grib_accessor* a, double* val, size_t* len)
|
||||
{
|
||||
int ret = 0;
|
||||
|
@ -176,8 +184,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
|
|||
long value_first = 0;
|
||||
char pressure_units[10] = {0,};
|
||||
size_t pressure_units_len = 10;
|
||||
long productionStatusOfProcessedData = 0;
|
||||
bool is_tigge = false;
|
||||
bool tigge = is_tigge(hand);
|
||||
|
||||
double v;
|
||||
|
||||
|
@ -190,10 +197,6 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
|
|||
if ((ret = grib_get_string_internal(hand, self->pressure_units, pressure_units, &pressure_units_len)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if ((ret = grib_get_long(hand, "productionStatusOfProcessedData", &productionStatusOfProcessedData)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
is_tigge = (productionStatusOfProcessedData==4 || productionStatusOfProcessedData==5);
|
||||
|
||||
if (value_first == GRIB_MISSING_LONG) {
|
||||
*val = 0;
|
||||
return GRIB_SUCCESS;
|
||||
|
@ -208,7 +211,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
|
|||
if (scale_first != GRIB_MISSING_LONG) {
|
||||
// GRIB-637, ECC-1081: Potential vorticity surface
|
||||
if (type_first == 109) {
|
||||
if (is_tigge) {
|
||||
if (tigge) {
|
||||
scale_first -= 6; // TIGGE data follows different rules
|
||||
} else {
|
||||
scale_first -= 9;
|
||||
|
@ -329,12 +332,11 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len)
|
|||
long type_first = 0;
|
||||
char pressure_units[10] = {0,};
|
||||
size_t pressure_units_len = 10;
|
||||
bool is_tigge = false;
|
||||
long productionStatusOfProcessedData = 0;
|
||||
|
||||
grib_accessor_g2level* self = (grib_accessor_g2level*)a;
|
||||
grib_handle* hand = grib_handle_of_accessor(a);
|
||||
int change_scale_and_value = 1;
|
||||
bool tigge = is_tigge(hand);
|
||||
|
||||
if (*len != 1)
|
||||
return GRIB_WRONG_ARRAY_SIZE;
|
||||
|
@ -354,18 +356,14 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len)
|
|||
if ((ret = grib_get_string_internal(hand, self->pressure_units, pressure_units, &pressure_units_len)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if ((ret = grib_get_long(hand, "productionStatusOfProcessedData", &productionStatusOfProcessedData)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
is_tigge = (productionStatusOfProcessedData==4 || productionStatusOfProcessedData==5);
|
||||
|
||||
switch (type_first) {
|
||||
case 100: // Pa
|
||||
scale_first = 0;
|
||||
if (!strcmp(pressure_units, "hPa"))
|
||||
value_first *= 100;
|
||||
break;
|
||||
case 109: // Potential vorticity surface
|
||||
if (!is_tigge) {
|
||||
case 109: // Potential vorticity surface (See ECC-1081)
|
||||
if (!tigge) {
|
||||
scale_first = 9;
|
||||
} else {
|
||||
scale_first = 6; // TIGGE data follows different rules
|
||||
|
|
Loading…
Reference in New Issue