Examples: cpplint warning [runtime/threadsafe_fn]

This commit is contained in:
Shahram Najm 2023-04-19 10:58:21 +01:00
parent 8ac436a104
commit 168537f503
3 changed files with 21 additions and 20 deletions

View File

@ -22,6 +22,7 @@ int main()
int i = 0; int i = 0;
codes_handle* h = NULL; codes_handle* h = NULL;
const char* filename = "bigfile.grib"; const char* filename = "bigfile.grib";
unsigned int seed = time(NULL);
numbytes = ni * nj * sizeof(double); numbytes = ni * nj * sizeof(double);
values = (double*)malloc(numbytes); values = (double*)malloc(numbytes);
@ -31,7 +32,7 @@ int main()
} }
for (i = 0; i < ni * nj; i++) { 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; values[i] = r;
} }
@ -65,7 +66,6 @@ int main()
CODES_CHECK(codes_set_double_array(h, "values", values, ni * nj), 0); CODES_CHECK(codes_set_double_array(h, "values", values, ni * nj), 0);
codes_write_message(h, filename, "w"); codes_write_message(h, filename, "w");
/*printf("Wrote file %s\n", filename);*/
codes_handle_delete(h); codes_handle_delete(h);
free(values); free(values);

View File

@ -9,10 +9,13 @@
. ./include.ctest.sh . ./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 ${examples_dir}/c_large_grib1
# Make sure the newly created file can be listed OK # Make sure the newly created file can be listed OK
output=bigfile.grib ${tools_dir}/grib_ls -p numberOfDataPoints,numberOfCodedValues,numberOfMissing $output
${tools_dir}/grib_ls $output > /dev/null num=$(${tools_dir}/grib_get -p numberOfDataPoints $output)
[ $num = 8294400 ]
rm -f $output rm -f $output

View File

@ -165,6 +165,14 @@ static void dump(grib_accessor* a, grib_dumper* dumper)
grib_dump_long(dumper, a, NULL); 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) static int unpack_double(grib_accessor* a, double* val, size_t* len)
{ {
int ret = 0; int ret = 0;
@ -176,8 +184,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
long value_first = 0; long value_first = 0;
char pressure_units[10] = {0,}; char pressure_units[10] = {0,};
size_t pressure_units_len = 10; size_t pressure_units_len = 10;
long productionStatusOfProcessedData = 0; bool tigge = is_tigge(hand);
bool is_tigge = false;
double v; 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) if ((ret = grib_get_string_internal(hand, self->pressure_units, pressure_units, &pressure_units_len)) != GRIB_SUCCESS)
return ret; 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) { if (value_first == GRIB_MISSING_LONG) {
*val = 0; *val = 0;
return GRIB_SUCCESS; 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) { if (scale_first != GRIB_MISSING_LONG) {
// GRIB-637, ECC-1081: Potential vorticity surface // GRIB-637, ECC-1081: Potential vorticity surface
if (type_first == 109) { if (type_first == 109) {
if (is_tigge) { if (tigge) {
scale_first -= 6; // TIGGE data follows different rules scale_first -= 6; // TIGGE data follows different rules
} else { } else {
scale_first -= 9; scale_first -= 9;
@ -329,12 +332,11 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len)
long type_first = 0; long type_first = 0;
char pressure_units[10] = {0,}; char pressure_units[10] = {0,};
size_t pressure_units_len = 10; size_t pressure_units_len = 10;
bool is_tigge = false;
long productionStatusOfProcessedData = 0;
grib_accessor_g2level* self = (grib_accessor_g2level*)a; grib_accessor_g2level* self = (grib_accessor_g2level*)a;
grib_handle* hand = grib_handle_of_accessor(a); grib_handle* hand = grib_handle_of_accessor(a);
int change_scale_and_value = 1; int change_scale_and_value = 1;
bool tigge = is_tigge(hand);
if (*len != 1) if (*len != 1)
return GRIB_WRONG_ARRAY_SIZE; 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) if ((ret = grib_get_string_internal(hand, self->pressure_units, pressure_units, &pressure_units_len)) != GRIB_SUCCESS)
return ret; return ret;
if ((ret = grib_get_long(hand, "productionStatusOfProcessedData", &productionStatusOfProcessedData)) != GRIB_SUCCESS)
return ret;
is_tigge = (productionStatusOfProcessedData==4 || productionStatusOfProcessedData==5);
switch (type_first) { switch (type_first) {
case 100: // Pa case 100: // Pa
scale_first = 0; scale_first = 0;
if (!strcmp(pressure_units, "hPa")) if (!strcmp(pressure_units, "hPa"))
value_first *= 100; value_first *= 100;
break; break;
case 109: // Potential vorticity surface case 109: // Potential vorticity surface (See ECC-1081)
if (!is_tigge) { if (!tigge) {
scale_first = 9; scale_first = 9;
} else { } else {
scale_first = 6; // TIGGE data follows different rules scale_first = 6; // TIGGE data follows different rules