14 #include "nc4internal.h"
15 #include "nc4dispatch.h"
17 #include "hdf5internal.h"
22 #define DEFAULT_1D_UNLIM_SIZE (4096)
28 # define M_LN10 2.30258509299404568402
31 # define M_LN2 0.69314718055994530942
38 #define BIT_XPL_NBR_SGN_FLT (23)
44 #define BIT_XPL_NBR_SGN_DBL (52)
51 unsigned long long *ui64p;
72 NC4_get_var_chunk_cache(
int ncid,
int varid,
size_t *sizep,
73 size_t *nelemsp,
float *preemptionp)
82 if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
84 assert(nc && grp && h5);
87 var = (NC_VAR_INFO_T*)ncindexith(grp->vars,varid);
90 assert(var && var->hdr.id == varid);
94 *sizep = var->chunkcache.size;
96 *nelemsp = var->chunkcache.nelems;
98 *preemptionp = var->chunkcache.preemption;
120 nc_get_var_chunk_cache_ints(
int ncid,
int varid,
int *sizep,
121 int *nelemsp,
int *preemptionp)
123 size_t real_size, real_nelems;
124 float real_preemption;
127 if ((ret = NC4_get_var_chunk_cache(ncid, varid, &real_size,
128 &real_nelems, &real_preemption)))
132 *sizep = real_size / MEGABYTE;
134 *nelemsp = (int)real_nelems;
136 *preemptionp = (int)(real_preemption * 100);
179 NC4_inq_var_all(
int ncid,
int varid,
char *name,
nc_type *xtypep,
180 int *ndimsp,
int *dimidsp,
int *nattsp,
181 int *shufflep,
int *deflatep,
int *deflate_levelp,
182 int *fletcher32p,
int *storagep,
size_t *chunksizesp,
183 int *no_fill,
void *fill_valuep,
int *endiannessp,
184 unsigned int *idp,
size_t *nparamsp,
unsigned int *params)
192 LOG((2,
"%s: ncid 0x%x varid %d", __func__, ncid, varid));
195 if ((retval = nc4_find_nc_grp_h5(ncid, NULL, &grp, &h5)))
202 *nattsp = ncindexcount(grp->att);
207 if (!(var = (NC_VAR_INFO_T *)ncindexith(grp->vars, varid)))
209 assert(var && var->hdr.id == varid);
213 strcpy(name, var->hdr.name);
215 *xtypep = var->type_info->hdr.id;
217 *ndimsp = var->ndims;
219 for (d = 0; d < var->ndims; d++)
220 dimidsp[d] = var->dimids[d];
222 *nattsp = ncindexcount(var->att);
225 if (var->storage ==
NC_CHUNKED && chunksizesp)
227 for (d = 0; d < var->ndims; d++)
229 chunksizesp[d] = var->chunksizes[d];
230 LOG((4,
"chunksizesp[%d]=%d", d, chunksizesp[d]));
236 *storagep = var->storage;
242 *shufflep = (retval ==
NC_NOERR?1:0);
247 *fletcher32p = (retval ==
NC_NOERR?1:0);
258 *no_fill = (int)var->no_fill;
262 if (!var->no_fill && fill_valuep)
268 if (var->type_info->nc_type_class ==
NC_STRING)
270 assert(*(
char **)var->fill_value);
272 if (!(*(
char **)fill_valuep = strdup(*(
char **)var->fill_value)))
274 free(*(
char **)fill_valuep);
280 assert(var->type_info->size);
281 memcpy(fill_valuep, var->fill_value, var->type_info->size);
286 int xtype = var->type_info->hdr.id;
287 if((retval =
nc_copy_data(ncid,xtype,var->fill_value,1,fill_valuep)))
return retval;
293 if (var->type_info->nc_type_class ==
NC_STRING)
295 if (!(*(
char **)fill_valuep = calloc(1,
sizeof(
char *))))
298 if ((retval = nc4_get_default_fill_value(var->type_info->hdr.ud, (
char **)fill_valuep)))
300 free(*(
char **)fill_valuep);
306 if ((retval = nc4_get_default_fill_value(var->type_info->hdr.id, fill_valuep)))
310 if ((retval = nc4_get_default_fill_value(var->type_info, fill_valuep)))
318 *endiannessp = var->endianness;
340 nc_inq_var_chunking_ints(
int ncid,
int varid,
int *storagep,
int *chunksizesp)
347 if ((retval = nc4_find_grp_h5_var(ncid, varid, NULL, NULL, &var)))
353 if (!(cs = malloc(var->ndims *
sizeof(
size_t))))
357 retval = NC4_inq_var_all(ncid, varid, NULL, NULL, NULL, NULL, NULL,
358 NULL, NULL, NULL, NULL, storagep, cs, NULL,
359 NULL, NULL, NULL, NULL, NULL);
362 if (!retval && chunksizesp && var->storage ==
NC_CHUNKED)
364 for (i = 0; i < var->ndims; i++)
366 chunksizesp[i] = (int)cs[i];
390 NC4_inq_varid(
int ncid,
const char *name,
int *varidp)
403 LOG((2,
"%s: ncid 0x%x name %s", __func__, ncid, name));
406 if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, NULL)))
410 if ((retval = nc4_normalize_name(name, norm_name)))
414 var = (NC_VAR_INFO_T*)ncindexlookup(grp->vars,norm_name);
417 *varidp = var->hdr.id;
442 NC4_var_par_access(
int ncid,
int varid,
int par_access)
444 #ifndef USE_PARALLEL4
447 NC_UNUSED(par_access);
456 LOG((1,
"%s: ncid 0x%x varid %d par_access %d", __func__, ncid,
463 if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
471 var = (NC_VAR_INFO_T*)ncindexith(grp->vars,varid);
473 assert(var->hdr.id == varid);
478 if (nclistlength((NClist*)var->filters) > 0 &&
523 nc4_convert_type(
const void *src,
void *dest,
const nc_type src_type,
524 const nc_type dest_type,
const size_t len,
int *range_error,
525 const void *fill_value,
int strict_nc3,
int quantize_mode,
533 double mnt_log10_fabs;
535 double mss_val_cmp_dbl;
536 float mss_val_cmp_flt;
542 unsigned int *u32_ptr;
543 unsigned int msk_f32_u32_zro;
544 unsigned int msk_f32_u32_one;
545 unsigned int msk_f32_u32_hshv;
546 unsigned long long int *u64_ptr;
547 unsigned long long int msk_f64_u64_zro;
548 unsigned long long int msk_f64_u64_one;
549 unsigned long long int msk_f64_u64_hshv;
550 unsigned short prc_bnr_xpl_rqr;
558 signed char *bp, *bp1;
559 unsigned char *ubp, *ubp1;
560 unsigned short *usp, *usp1;
561 unsigned int *uip, *uip1;
562 long long *lip, *lip1;
563 unsigned long long *ulip, *ulip1;
567 LOG((3,
"%s: len %d src_type %d dest_type %d", __func__, len, src_type,
581 mss_val_cmp_flt = *(
float *)fill_value;
591 mss_val_cmp_dbl = *(
double *)fill_value;
612 prc_bnr_xpl_rqr = (
unsigned short)ceil(nsd * bit_per_dgt) + 1;
617 prc_bnr_xpl_rqr = nsd;
627 msk_f32_u32_zro = 0u;
628 msk_f32_u32_zro = ~msk_f32_u32_zro;
632 msk_f32_u32_zro <<= bit_xpl_nbr_zro;
636 msk_f32_u32_one = ~msk_f32_u32_zro;
639 msk_f32_u32_hshv=msk_f32_u32_one & (msk_f32_u32_zro >> 1);
647 msk_f64_u64_zro = 0ul;
648 msk_f64_u64_zro = ~msk_f64_u64_zro;
652 msk_f64_u64_zro <<= bit_xpl_nbr_zro;
656 msk_f64_u64_one =~ msk_f64_u64_zro;
659 msk_f64_u64_hshv = msk_f64_u64_one & (msk_f64_u64_zro >> 1);
681 for (cp = (
char *)src, cp1 = dest; count < len; count++)
685 LOG((0,
"%s: Unknown destination type.", __func__));
693 for (bp = (
signed char *)src, bp1 = dest; count < len; count++)
697 for (bp = (
signed char *)src, ubp = dest; count < len; count++)
705 for (bp = (
signed char *)src, sp = dest; count < len; count++)
709 for (bp = (
signed char *)src, usp = dest; count < len; count++)
717 for (bp = (
signed char *)src, ip = dest; count < len; count++)
721 for (bp = (
signed char *)src, uip = dest; count < len; count++)
729 for (bp = (
signed char *)src, lip = dest; count < len; count++)
733 for (bp = (
signed char *)src, ulip = dest; count < len; count++)
741 for (bp = (
signed char *)src, fp = dest; count < len; count++)
745 for (bp = (
signed char *)src, dp = dest; count < len; count++)
749 LOG((0,
"%s: unexpected dest type. src_type %d, dest_type %d",
750 __func__, src_type, dest_type));
759 for (ubp = (
unsigned char *)src, bp = dest; count < len; count++)
761 if (!strict_nc3 && *ubp > X_SCHAR_MAX)
767 for (ubp = (
unsigned char *)src, sp = dest; count < len; count++)
771 for (ubp = (
unsigned char *)src, ubp1 = dest; count < len; count++)
775 for (ubp = (
unsigned char *)src, usp = dest; count < len; count++)
779 for (ubp = (
unsigned char *)src, ip = dest; count < len; count++)
783 for (ubp = (
unsigned char *)src, uip = dest; count < len; count++)
787 for (ubp = (
unsigned char *)src, lip = dest; count < len; count++)
791 for (ubp = (
unsigned char *)src, ulip = dest; count < len; count++)
795 for (ubp = (
unsigned char *)src, fp = dest; count < len; count++)
799 for (ubp = (
unsigned char *)src, dp = dest; count < len; count++)
803 LOG((0,
"%s: unexpected dest type. src_type %d, dest_type %d",
804 __func__, src_type, dest_type));
813 for (sp = (
short *)src, ubp = dest; count < len; count++)
815 if (*sp > X_UCHAR_MAX || *sp < 0)
821 for (sp = (
short *)src, bp = dest; count < len; count++)
823 if (*sp > X_SCHAR_MAX || *sp < X_SCHAR_MIN)
829 for (sp = (
short *)src, sp1 = dest; count < len; count++)
833 for (sp = (
short *)src, usp = dest; count < len; count++)
841 for (sp = (
short *)src, ip = dest; count < len; count++)
845 for (sp = (
short *)src, uip = dest; count < len; count++)
853 for (sp = (
short *)src, lip = dest; count < len; count++)
857 for (sp = (
short *)src, ulip = dest; count < len; count++)
865 for (sp = (
short *)src, fp = dest; count < len; count++)
869 for (sp = (
short *)src, dp = dest; count < len; count++)
873 LOG((0,
"%s: unexpected dest type. src_type %d, dest_type %d",
874 __func__, src_type, dest_type));
883 for (usp = (
unsigned short *)src, ubp = dest; count < len; count++)
885 if (*usp > X_UCHAR_MAX)
891 for (usp = (
unsigned short *)src, bp = dest; count < len; count++)
893 if (*usp > X_SCHAR_MAX)
899 for (usp = (
unsigned short *)src, sp = dest; count < len; count++)
901 if (*usp > X_SHORT_MAX)
907 for (usp = (
unsigned short *)src, usp1 = dest; count < len; count++)
911 for (usp = (
unsigned short *)src, ip = dest; count < len; count++)
915 for (usp = (
unsigned short *)src, uip = dest; count < len; count++)
919 for (usp = (
unsigned short *)src, lip = dest; count < len; count++)
923 for (usp = (
unsigned short *)src, ulip = dest; count < len; count++)
927 for (usp = (
unsigned short *)src, fp = dest; count < len; count++)
931 for (usp = (
unsigned short *)src, dp = dest; count < len; count++)
935 LOG((0,
"%s: unexpected dest type. src_type %d, dest_type %d",
936 __func__, src_type, dest_type));
945 for (ip = (
int *)src, ubp = dest; count < len; count++)
947 if (*ip > X_UCHAR_MAX || *ip < 0)
953 for (ip = (
int *)src, bp = dest; count < len; count++)
955 if (*ip > X_SCHAR_MAX || *ip < X_SCHAR_MIN)
961 for (ip = (
int *)src, sp = dest; count < len; count++)
963 if (*ip > X_SHORT_MAX || *ip < X_SHORT_MIN)
969 for (ip = (
int *)src, usp = dest; count < len; count++)
971 if (*ip > X_USHORT_MAX || *ip < 0)
977 for (ip = (
int *)src, ip1 = dest; count < len; count++)
979 if (*ip > X_INT_MAX || *ip < X_INT_MIN)
985 for (ip = (
int *)src, uip = dest; count < len; count++)
987 if (*ip > X_UINT_MAX || *ip < 0)
993 for (ip = (
int *)src, lip = dest; count < len; count++)
997 for (ip = (
int *)src, ulip = dest; count < len; count++)
1005 for (ip = (
int *)src, fp = dest; count < len; count++)
1009 for (ip = (
int *)src, dp = dest; count < len; count++)
1013 LOG((0,
"%s: unexpected dest type. src_type %d, dest_type %d",
1014 __func__, src_type, dest_type));
1023 for (uip = (
unsigned int *)src, ubp = dest; count < len; count++)
1025 if (*uip > X_UCHAR_MAX)
1031 for (uip = (
unsigned int *)src, bp = dest; count < len; count++)
1033 if (*uip > X_SCHAR_MAX)
1039 for (uip = (
unsigned int *)src, sp = dest; count < len; count++)
1041 if (*uip > X_SHORT_MAX)
1047 for (uip = (
unsigned int *)src, usp = dest; count < len; count++)
1049 if (*uip > X_USHORT_MAX)
1055 for (uip = (
unsigned int *)src, ip = dest; count < len; count++)
1057 if (*uip > X_INT_MAX)
1063 for (uip = (
unsigned int *)src, uip1 = dest; count < len; count++)
1065 if (*uip > X_UINT_MAX)
1071 for (uip = (
unsigned int *)src, lip = dest; count < len; count++)
1075 for (uip = (
unsigned int *)src, ulip = dest; count < len; count++)
1079 for (uip = (
unsigned int *)src, fp = dest; count < len; count++)
1083 for (uip = (
unsigned int *)src, dp = dest; count < len; count++)
1087 LOG((0,
"%s: unexpected dest type. src_type %d, dest_type %d",
1088 __func__, src_type, dest_type));
1097 for (lip = (
long long *)src, ubp = dest; count < len; count++)
1099 if (*lip > X_UCHAR_MAX || *lip < 0)
1105 for (lip = (
long long *)src, bp = dest; count < len; count++)
1107 if (*lip > X_SCHAR_MAX || *lip < X_SCHAR_MIN)
1113 for (lip = (
long long *)src, sp = dest; count < len; count++)
1115 if (*lip > X_SHORT_MAX || *lip < X_SHORT_MIN)
1121 for (lip = (
long long *)src, usp = dest; count < len; count++)
1123 if (*lip > X_USHORT_MAX || *lip < 0)
1129 for (lip = (
long long *)src, uip = dest; count < len; count++)
1131 if (*lip > X_UINT_MAX || *lip < 0)
1137 for (lip = (
long long *)src, ip = dest; count < len; count++)
1139 if (*lip > X_INT_MAX || *lip < X_INT_MIN)
1145 for (lip = (
long long *)src, lip1 = dest; count < len; count++)
1149 for (lip = (
long long *)src, ulip = dest; count < len; count++)
1157 for (lip = (
long long *)src, fp = dest; count < len; count++)
1161 for (lip = (
long long *)src, dp = dest; count < len; count++)
1165 LOG((0,
"%s: unexpected dest type. src_type %d, dest_type %d",
1166 __func__, src_type, dest_type));
1175 for (ulip = (
unsigned long long *)src, ubp = dest; count < len; count++)
1177 if (*ulip > X_UCHAR_MAX)
1183 for (ulip = (
unsigned long long *)src, bp = dest; count < len; count++)
1185 if (*ulip > X_SCHAR_MAX)
1191 for (ulip = (
unsigned long long *)src, sp = dest; count < len; count++)
1193 if (*ulip > X_SHORT_MAX)
1199 for (ulip = (
unsigned long long *)src, usp = dest; count < len; count++)
1201 if (*ulip > X_USHORT_MAX)
1207 for (ulip = (
unsigned long long *)src, uip = dest; count < len; count++)
1209 if (*ulip > X_UINT_MAX)
1215 for (ulip = (
unsigned long long *)src, ip = dest; count < len; count++)
1217 if (*ulip > X_INT_MAX)
1223 for (ulip = (
unsigned long long *)src, lip = dest; count < len; count++)
1225 if (*ulip > X_INT64_MAX)
1231 for (ulip = (
unsigned long long *)src, ulip1 = dest; count < len; count++)
1235 for (ulip = (
unsigned long long *)src, fp = dest; count < len; count++)
1239 for (ulip = (
unsigned long long *)src, dp = dest; count < len; count++)
1243 LOG((0,
"%s: unexpected dest type. src_type %d, dest_type %d",
1244 __func__, src_type, dest_type));
1253 for (fp = (
float *)src, ubp = dest; count < len; count++)
1255 if (*fp > X_UCHAR_MAX || *fp < 0)
1261 for (fp = (
float *)src, bp = dest; count < len; count++)
1263 if (*fp > (
double)X_SCHAR_MAX || *fp < (
double)X_SCHAR_MIN)
1269 for (fp = (
float *)src, sp = dest; count < len; count++)
1271 if (*fp > (
double)X_SHORT_MAX || *fp < (
double)X_SHORT_MIN)
1277 for (fp = (
float *)src, usp = dest; count < len; count++)
1279 if (*fp > X_USHORT_MAX || *fp < 0)
1285 for (fp = (
float *)src, uip = dest; count < len; count++)
1287 if (*fp > X_UINT_MAX || *fp < 0)
1293 for (fp = (
float *)src, ip = dest; count < len; count++)
1295 if (*fp > (
double)X_INT_MAX || *fp < (
double)X_INT_MIN)
1301 for (fp = (
float *)src, lip = dest; count < len; count++)
1303 if (*fp > X_INT64_MAX || *fp <X_INT64_MIN)
1309 for (fp = (
float *)src, lip = dest; count < len; count++)
1311 if (*fp > X_UINT64_MAX || *fp < 0)
1317 for (fp = (
float *)src, fp1 = dest; count < len; count++)
1321 for (fp = (
float *)src, dp = dest; count < len; count++)
1325 LOG((0,
"%s: unexpected dest type. src_type %d, dest_type %d",
1326 __func__, src_type, dest_type));
1335 for (dp = (
double *)src, ubp = dest; count < len; count++)
1337 if (*dp > X_UCHAR_MAX || *dp < 0)
1343 for (dp = (
double *)src, bp = dest; count < len; count++)
1345 if (*dp > X_SCHAR_MAX || *dp < X_SCHAR_MIN)
1351 for (dp = (
double *)src, sp = dest; count < len; count++)
1353 if (*dp > X_SHORT_MAX || *dp < X_SHORT_MIN)
1359 for (dp = (
double *)src, usp = dest; count < len; count++)
1361 if (*dp > X_USHORT_MAX || *dp < 0)
1367 for (dp = (
double *)src, uip = dest; count < len; count++)
1369 if (*dp > X_UINT_MAX || *dp < 0)
1375 for (dp = (
double *)src, ip = dest; count < len; count++)
1377 if (*dp > X_INT_MAX || *dp < X_INT_MIN)
1383 for (dp = (
double *)src, lip = dest; count < len; count++)
1385 if (*dp > X_INT64_MAX || *dp < X_INT64_MIN)
1391 for (dp = (
double *)src, lip = dest; count < len; count++)
1393 if (*dp > X_UINT64_MAX || *dp < 0)
1399 for (dp = (
double *)src, fp = dest; count < len; count++)
1401 if (isgreater(*dp, X_FLOAT_MAX) || isless(*dp, X_FLOAT_MIN))
1407 for (dp = (
double *)src, dp1 = dest; count < len; count++)
1411 LOG((0,
"%s: unexpected dest type. src_type %d, dest_type %d",
1412 __func__, src_type, dest_type));
1418 LOG((0,
"%s: unexpected src type. src_type %d, dest_type %d",
1419 __func__, src_type, dest_type));
1430 op1.fp = (
float *)dest;
1431 u32_ptr = op1.ui32p;
1432 for (idx = 0L; idx < len; idx += 2L)
1433 if (op1.fp[idx] != mss_val_cmp_flt)
1434 u32_ptr[idx] &= msk_f32_u32_zro;
1435 for (idx = 1L; idx < len; idx += 2L)
1436 if (op1.fp[idx] != mss_val_cmp_flt && u32_ptr[idx] != 0U)
1437 u32_ptr[idx] |= msk_f32_u32_one;
1442 op1.dp = (
double *)dest;
1443 u64_ptr = op1.ui64p;
1444 for (idx = 0L; idx < len; idx += 2L)
1445 if (op1.dp[idx] != mss_val_cmp_dbl)
1446 u64_ptr[idx] &= msk_f64_u64_zro;
1447 for (idx = 1L; idx < len; idx += 2L)
1448 if (op1.dp[idx] != mss_val_cmp_dbl && u64_ptr[idx] != 0ULL)
1449 u64_ptr[idx] |= msk_f64_u64_one;
1458 op1.fp = (
float *)dest;
1459 u32_ptr = op1.ui32p;
1460 for (idx = 0L; idx < len; idx++){
1461 if (op1.fp[idx] != mss_val_cmp_flt){
1462 u32_ptr[idx] += msk_f32_u32_hshv;
1463 u32_ptr[idx] &= msk_f32_u32_zro;
1470 op1.dp = (
double *)dest;
1471 u64_ptr = op1.ui64p;
1472 for (idx = 0L; idx < len; idx++){
1473 if (op1.dp[idx] != mss_val_cmp_dbl){
1474 u64_ptr[idx] += msk_f64_u64_hshv;
1475 u64_ptr[idx] &= msk_f64_u64_zro;
1486 op1.fp = (
float *)dest;
1487 u32_ptr = op1.ui32p;
1488 for (idx = 0L; idx < len; idx++)
1491 if((val = op1.fp[idx]) != mss_val_cmp_flt && u32_ptr[idx] != 0U)
1493 mnt = frexp(val, &xpn_bs2);
1494 mnt_fabs = fabs(mnt);
1495 mnt_log10_fabs = log10(mnt_fabs);
1497 dgt_nbr = (int)floor(xpn_bs2 * dgt_per_bit + mnt_log10_fabs) + 1;
1498 qnt_pwr = (int)floor(bit_per_dgt * (dgt_nbr - nsd));
1499 prc_bnr_xpl_rqr = mnt_fabs == 0.0 ? 0 : abs((
int)floor(xpn_bs2 - bit_per_dgt*mnt_log10_fabs) - qnt_pwr);
1503 msk_f32_u32_zro = 0u;
1504 msk_f32_u32_zro = ~msk_f32_u32_zro;
1506 msk_f32_u32_zro <<= bit_xpl_nbr_zro;
1508 msk_f32_u32_one = ~msk_f32_u32_zro;
1509 msk_f32_u32_hshv = msk_f32_u32_one & (msk_f32_u32_zro >> 1);
1510 u32_ptr[idx] += msk_f32_u32_hshv;
1511 u32_ptr[idx] &= msk_f32_u32_zro;
1520 op1.dp = (
double *)dest;
1521 u64_ptr = op1.ui64p;
1522 for (idx = 0L; idx < len; idx++)
1525 if((val = op1.dp[idx]) != mss_val_cmp_dbl && u64_ptr[idx] != 0ULL)
1527 mnt = frexp(val, &xpn_bs2);
1528 mnt_fabs = fabs(mnt);
1529 mnt_log10_fabs = log10(mnt_fabs);
1531 dgt_nbr = (int)floor(xpn_bs2 * dgt_per_bit + mnt_log10_fabs) + 1;
1532 qnt_pwr = (int)floor(bit_per_dgt * (dgt_nbr - nsd));
1533 prc_bnr_xpl_rqr = mnt_fabs == 0.0 ? 0 : abs((
int)floor(xpn_bs2 - bit_per_dgt*mnt_log10_fabs) - qnt_pwr);
1537 msk_f64_u64_zro = 0ull;
1538 msk_f64_u64_zro = ~msk_f64_u64_zro;
1540 msk_f64_u64_zro <<= bit_xpl_nbr_zro;
1542 msk_f64_u64_one = ~msk_f64_u64_zro;
1543 msk_f64_u64_hshv = msk_f64_u64_one & (msk_f64_u64_zro >> 1);
1544 u64_ptr[idx] += msk_f64_u64_hshv;
1545 u64_ptr[idx] &= msk_f64_u64_zro;
1568 nc4_get_fill_value(NC_FILE_INFO_T *h5, NC_VAR_INFO_T *var,
void **fillp)
1574 if (var->type_info->nc_type_class ==
NC_VLEN)
1576 else if (var->type_info->nc_type_class ==
NC_STRING)
1577 size =
sizeof(
char *);
1580 if ((retval = nc4_get_typelen_mem(h5, var->type_info->hdr.id, &size)))
1586 if (!((*fillp) = calloc(1, size)))
1591 if (var->fill_value)
1593 LOG((4,
"Found a fill value for var %s", var->hdr.name));
1594 if (var->type_info->nc_type_class ==
NC_VLEN)
1597 size_t basetypesize = 0;
1599 if((retval=nc4_get_typelen_mem(h5, var->type_info->u.v.base_nc_typeid, &basetypesize)))
1602 fv_vlen->
len = in_vlen->
len;
1603 if (!(fv_vlen->p = malloc(basetypesize * in_vlen->
len)))
1609 memcpy(fv_vlen->p, in_vlen->
p, in_vlen->
len * basetypesize);
1611 else if (var->type_info->nc_type_class ==
NC_STRING)
1613 if (*(
char **)var->fill_value)
1614 if (!(**(
char ***)fillp = strdup(*(
char **)var->fill_value)))
1622 memcpy((*fillp), var->fill_value, size);
1626 if (nc4_get_default_fill_value(var->type_info, *fillp))
1650 nc4_get_typelen_mem(NC_FILE_INFO_T *h5,
nc_type xtype,
size_t *len)
1652 NC_TYPE_INFO_T *type;
1655 LOG((4,
"%s xtype: %d", __func__, xtype));
1664 *len =
sizeof(char);
1668 *len =
sizeof(short);
1675 *len =
sizeof(float);
1678 *len =
sizeof(double);
1682 *len =
sizeof(
long long);
1685 *len =
sizeof(
char *);
1690 if ((retval = nc4_find_type(h5, xtype, &type)))
1698 LOG((5,
"type->size: %d", type->size));
1718 nc4_check_chunksizes(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var,
const size_t *chunksizes)
1725 if ((retval = nc4_get_typelen_mem(grp->nc4_info, var->type_info->hdr.id, &type_len)))
1727 if (var->type_info->nc_type_class ==
NC_VLEN)
1730 dprod = (double)type_len;
1731 for (d = 0; d < var->ndims; d++)
1732 dprod *= (
double)chunksizes[d];
1752 nc4_find_default_chunksizes2(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var)
1756 float num_values = 1, num_unlim = 0;
1758 size_t suggested_size;
1760 double total_chunk_size;
1763 if (var->type_info->nc_type_class ==
NC_STRING)
1764 type_size =
sizeof(
char *);
1766 type_size = var->type_info->size;
1771 total_chunk_size = (double) type_size;
1774 if(var->chunksizes == NULL) {
1775 if((var->chunksizes = calloc(1,
sizeof(
size_t)*var->ndims)) == NULL)
1781 for (d = 0; d < var->ndims; d++)
1783 assert(var->dim[d]);
1784 if (! var->dim[d]->unlimited)
1785 num_values *= (float)var->dim[d]->len;
1788 var->chunksizes[d] = 1;
1794 if (var->ndims == 1 && num_unlim == 1) {
1795 if (DEFAULT_CHUNK_SIZE / type_size <= 0)
1797 else if (DEFAULT_CHUNK_SIZE / type_size > DEFAULT_1D_UNLIM_SIZE)
1798 suggested_size = DEFAULT_1D_UNLIM_SIZE;
1800 suggested_size = DEFAULT_CHUNK_SIZE / type_size;
1801 var->chunksizes[0] = suggested_size / type_size;
1802 LOG((4,
"%s: name %s dim %d DEFAULT_CHUNK_SIZE %d num_values %f type_size %d "
1803 "chunksize %ld", __func__, var->hdr.name, d, DEFAULT_CHUNK_SIZE, num_values, type_size, var->chunksizes[0]));
1805 if (var->ndims > 1 && var->ndims == num_unlim) {
1806 suggested_size = pow((
double)DEFAULT_CHUNK_SIZE/type_size, 1.0/(
double)(var->ndims));
1807 for (d = 0; d < var->ndims; d++)
1809 var->chunksizes[d] = suggested_size ? suggested_size : 1;
1810 LOG((4,
"%s: name %s dim %d DEFAULT_CHUNK_SIZE %d num_values %f type_size %d "
1811 "chunksize %ld", __func__, var->hdr.name, d, DEFAULT_CHUNK_SIZE, num_values, type_size, var->chunksizes[d]));
1817 for (d = 0; d < var->ndims; d++)
1818 if (!var->chunksizes[d])
1820 suggested_size = (pow((
double)DEFAULT_CHUNK_SIZE/(num_values * type_size),
1821 1.0/(
double)(var->ndims - num_unlim)) * var->dim[d]->len - .5);
1822 if (suggested_size > var->dim[d]->len)
1823 suggested_size = var->dim[d]->len;
1824 var->chunksizes[d] = suggested_size ? suggested_size : 1;
1825 LOG((4,
"%s: name %s dim %d DEFAULT_CHUNK_SIZE %d num_values %f type_size %d "
1826 "chunksize %ld", __func__, var->hdr.name, d, DEFAULT_CHUNK_SIZE, num_values, type_size, var->chunksizes[d]));
1831 for (d = 0; d < var->ndims; d++)
1832 total_chunk_size *= (
double) var->chunksizes[d];
1833 LOG((4,
"total_chunk_size %f", total_chunk_size));
1837 retval = nc4_check_chunksizes(grp, var, var->chunksizes);
1845 for ( ; retval ==
NC_EBADCHUNK; retval = nc4_check_chunksizes(grp, var, var->chunksizes))
1846 for (d = 0; d < var->ndims; d++)
1847 var->chunksizes[d] = var->chunksizes[d]/2 ? var->chunksizes[d]/2 : 1;
1853 for (d = 0; d < var->ndims; d++)
1857 assert(var->chunksizes[d] > 0);
1858 num_chunks = (var->dim[d]->len + var->chunksizes[d] - 1) / var->chunksizes[d];
1859 if(num_chunks > 0) {
1860 overhang = (num_chunks * var->chunksizes[d]) - var->dim[d]->len;
1861 var->chunksizes[d] -= overhang / num_chunks;
1881 nc4_get_default_fill_value(NC_TYPE_INFO_T* tinfo,
void *fill_value)
1883 if(tinfo->hdr.id >
NC_NAT && tinfo->hdr.id <= NC_MAX_ATOMIC_TYPE)
1884 return nc4_get_default_atomic_fill_value(tinfo->hdr.id,fill_value);
1886 switch(tinfo->nc_type_class) {
1888 return nc4_get_default_atomic_fill_value(tinfo->u.e.base_nc_typeid,fill_value);
1893 memset(fill_value,0,tinfo->size);
1913 nc4_get_default_atomic_fill_value(
nc_type xtype,
void *fill_value)
EXTERNL int nc_inq_var_filter_info(int ncid, int varid, unsigned int id, size_t *nparams, unsigned int *params)
Find the the param info about filter (if any) associated with a variable and with specified id.
#define BIT_XPL_NBR_SGN_DBL
Used in quantize code.
#define BIT_XPL_NBR_SGN_FLT
Used in quantize code.
#define NC_EBADTYPE
Not a netcdf data type.
#define NC_UINT
unsigned 4-byte int
#define NC_FILL_BYTE
Default fill value.
void * p
Pointer to VL data.
#define NC_EFILTER
Filter operation failed.
#define NC_INT
signed 4 byte integer
#define NC_FILL_INT
Default fill value.
#define NC_BYTE
signed 1 byte integer
#define NC_QUANTIZE_BITROUND
Use BitRound quantization.
size_t len
Length of VL data (in base type units)
#define NC_VLEN
vlen (variable-length) types
#define NC_FILL_UBYTE
Default fill value.
#define NC_NAT
Not A Type.
#define NC_MAX_UINT
Max or min values for a type.
#define NC_DOUBLE
double precision floating point number
#define NC_UBYTE
unsigned 1 byte int
#define NC_FLOAT
single precision floating point number
#define NC_ENOMEM
Memory allocation (malloc) failure.
#define NC_MAX_INT
Max or min values for a type.
#define NC_COMPOUND
compound types
EXTERNL int nc_copy_data(int ncid, nc_type xtypeid, const void *memory, size_t count, void *copy)
Copy vector of arbitrary type instances.
#define NC_CHUNKED
In HDF5 files you can set storage for each variable to be either contiguous or chunked,...
#define NC_SHORT
signed 2 byte integer
#define NC_QUANTIZE_GRANULARBR
Use Granular BitRound quantization.
#define NC_FILL_UINT64
Default fill value.
#define NC_QUANTIZE_BITGROOM
Use BitGroom quantization.
#define NC_ENUM
enum types
#define NC_INT64
signed 8-byte int
#define NC_GLOBAL
Attribute id to put/get a global attribute.
#define NC_FILL_UINT
Default fill value.
#define NC_FILL_CHAR
Default fill value.
#define NC_UINT64
unsigned 8-byte int
#define NC_ENOTVAR
Variable not found.
#define NC_EINVAL
Invalid Argument.
#define NC_MAX_NAME
Maximum for classic library.
#define NC_NOERR
No Error.
#define NC_FILL_USHORT
Default fill value.
#define NC_FILL_SHORT
Default fill value.
#define NC_FILL_INT64
Default fill value.
#define NC_NOQUANTIZE
No quantization in use.
#define NC_USHORT
unsigned 2-byte int
#define NC_OPAQUE
opaque types
#define NC_ENOPAR
Parallel operation on file opened for non-parallel access.
#define NC_EBADCHUNK
Bad chunksize.
#define NC_FILL_FLOAT
Default fill value.
#define NC_ENOFILTER
Filter not defined on variable.
#define NC_FILL_DOUBLE
Default fill value.
#define NC_CHAR
ISO/ASCII character.
#define NC_ERANGE
Math result not representable.
#define NC_FILL_STRING
Default fill value.
int nc_type
The nc_type type is just an int.
This is the type of arrays of vlens.
#define NC_COLLECTIVE
Use with nc_var_par_access() to set parallel access to collective.
#define NC_INDEPENDENT
Use with nc_var_par_access() to set parallel access to independent.