Single-precision mode

This commit is contained in:
Shahram Najm 2023-06-22 22:46:16 +01:00
parent 0c2b2380da
commit db517e6ce1
1 changed files with 32 additions and 25 deletions

View File

@ -2781,43 +2781,50 @@ int grib_f_get_real4(int* gid, char* key, float* val, int len){
return grib_f_get_real4_( gid, key, val, len); return grib_f_get_real4_( gid, key, val, len);
} }
int grib_f_get_real4_array_(int* gid, char* key, float *val, int* size, int len) int grib_f_get_real4_array_(int* gid, char* key, float* val, int* size, int len)
{ {
/* See ECC-1579: /* See ECC-1579:
* Ideally we should be calling: * Ideally we should ALWAYS be calling:
* err = grib_get_float_array(h, cast_char(buf,key,len), val, &lsize); * err = grib_get_float_array(h, cast_char(buf,key,len), val, &lsize);
* */
*/
grib_handle *h = get_handle(*gid); grib_handle* h = get_handle(*gid);
int err = GRIB_SUCCESS; size_t lsize = *size;
char buf[1024]; char buf[1024];
size_t lsize = *size; int err = GRIB_SUCCESS;
double* val8 = NULL; const int single_precision_mode = (h->context->single_precision != 0);
size_t i;
if(!h) return GRIB_INVALID_GRIB; if (!h) return GRIB_INVALID_GRIB;
if(*size) if (single_precision_mode) {
val8 = (double*)grib_context_malloc(h->context,(*size)*(sizeof(double))); err = grib_get_float_array(h, cast_char(buf, key, len), val, &lsize);
else }
val8 = (double*)grib_context_malloc(h->context,sizeof(double)); else {
double* val8 = NULL;
size_t i;
if(!val8) return GRIB_OUT_OF_MEMORY; if (*size)
val8 = (double*)grib_context_malloc(h->context, (*size) * (sizeof(double)));
else
val8 = (double*)grib_context_malloc(h->context, sizeof(double));
err = grib_get_double_array(h, cast_char(buf,key,len), val8, &lsize); if (!val8) return GRIB_OUT_OF_MEMORY;
if (err) {
grib_context_free(h->context,val8); err = grib_get_double_array(h, cast_char(buf, key, len), val8, &lsize);
return err; if (err) {
grib_context_free(h->context, val8);
return err;
}
for (i = 0; i < lsize; i++)
val[i] = val8[i];
grib_context_free(h->context, val8);
} }
for(i=0;i<lsize;i++) return err;
val[i] = val8[i];
grib_context_free(h->context,val8);
return err;
} }
int grib_f_get_real4_array__(int* gid, char* key, float* val, int* size, int len){ int grib_f_get_real4_array__(int* gid, char* key, float* val, int* size, int len){
return grib_f_get_real4_array_( gid, key, val, size, len); return grib_f_get_real4_array_( gid, key, val, size, len);
} }