19 #include "nc4internal.h"
20 #include "ncdispatch.h"
21 #include "hdf5internal.h"
24 #ifdef HAVE_INTTYPES_H
25 #define __STDC_FORMAT_MACROS
29 #define NC_HDF5_MAX_NAME 1024
40 flag_atts_dirty(NCindex *attlist) {
42 NC_ATT_INFO_T *att = NULL;
49 for(i=0;i<ncindexsize(attlist);i++) {
50 att = (NC_ATT_INFO_T*)ncindexith(attlist,i);
51 if(att == NULL)
continue;
75 rec_reattach_scales(NC_GRP_INFO_T *grp,
int dimid, hid_t dimscaleid)
78 NC_GRP_INFO_T *child_grp;
82 assert(grp && grp->hdr.name && dimid >= 0 && dimscaleid >= 0);
83 LOG((3,
"%s: grp->hdr.name %s", __func__, grp->hdr.name));
86 for (i = 0; i < ncindexsize(grp->children); i++)
88 child_grp = (NC_GRP_INFO_T*)ncindexith(grp->children, i);
90 if ((retval = rec_reattach_scales(child_grp, dimid, dimscaleid)))
95 for (i = 0; i < ncindexsize(grp->vars); i++)
97 NC_HDF5_VAR_INFO_T *hdf5_var;
99 var = (NC_VAR_INFO_T*)ncindexith(grp->vars,i);
100 assert(var && var->format_var_info);
101 hdf5_var = (NC_HDF5_VAR_INFO_T *)var->format_var_info;
103 for (d = 0; d < var->ndims; d++)
105 if (var->dimids[d] == dimid && !var->dimscale)
107 LOG((2,
"%s: attaching scale for dimid %d to var %s",
108 __func__, var->dimids[d], var->hdr.name));
111 if (H5DSattach_scale(hdf5_var->hdf_datasetid,
114 var->dimscale_attached[d] = NC_TRUE;
139 rec_detach_scales(NC_GRP_INFO_T *grp,
int dimid, hid_t dimscaleid)
142 NC_GRP_INFO_T *child_grp;
146 assert(grp && grp->hdr.name && dimid >= 0 && dimscaleid >= 0);
147 LOG((3,
"%s: grp->hdr.name %s", __func__, grp->hdr.name));
150 for(i=0;i<ncindexsize(grp->children);i++) {
151 child_grp = (NC_GRP_INFO_T*)ncindexith(grp->children,i);
152 if(child_grp == NULL)
continue;
153 if ((retval = rec_detach_scales(child_grp, dimid, dimscaleid)))
158 for (i = 0; i < ncindexsize(grp->vars); i++)
160 NC_HDF5_VAR_INFO_T *hdf5_var;
161 var = (NC_VAR_INFO_T*)ncindexith(grp->vars, i);
162 assert(var && var->format_var_info);
163 hdf5_var = (NC_HDF5_VAR_INFO_T *)var->format_var_info;
165 for (d = 0; d < var->ndims; d++)
167 if (var->dimids[d] == dimid && !var->dimscale)
169 LOG((2,
"%s: detaching scale for dimid %d to var %s",
170 __func__, var->dimids[d], var->hdr.name));
173 if (var->dimscale_attached && var->dimscale_attached[d])
175 if (H5DSdetach_scale(hdf5_var->hdf_datasetid,
178 var->dimscale_attached[d] = NC_FALSE;
199 nc4_open_var_grp2(NC_GRP_INFO_T *grp,
int varid, hid_t *dataset)
202 NC_HDF5_VAR_INFO_T *hdf5_var;
204 assert(grp && grp->format_grp_info && dataset);
207 if (!(var = (NC_VAR_INFO_T *)ncindexith(grp->vars, varid)))
209 assert(var && var->hdr.id == varid && var->format_var_info);
210 hdf5_var = (NC_HDF5_VAR_INFO_T *)var->format_var_info;
213 if (!hdf5_var->hdf_datasetid)
215 NC_HDF5_GRP_INFO_T *hdf5_grp;
216 hdf5_grp = (NC_HDF5_GRP_INFO_T *)grp->format_grp_info;
218 if ((hdf5_var->hdf_datasetid = H5Dopen2(hdf5_grp->hdf_grpid,
219 var->hdr.name, H5P_DEFAULT)) < 0)
223 *dataset = hdf5_var->hdf_datasetid;
240 nc4_get_fill_value(NC_FILE_INFO_T *h5, NC_VAR_INFO_T *var,
void **fillp)
246 if (var->type_info->nc_type_class ==
NC_VLEN)
248 else if (var->type_info->nc_type_class ==
NC_STRING)
249 size =
sizeof(
char *);
252 if ((retval = nc4_get_typelen_mem(h5, var->type_info->hdr.id, &size)))
258 if (!((*fillp) = calloc(1, size)))
265 LOG((4,
"Found a fill value for var %s", var->hdr.name));
266 if (var->type_info->nc_type_class ==
NC_VLEN)
269 size_t basetypesize = 0;
271 if((retval=nc4_get_typelen_mem(h5, var->type_info->u.v.base_nc_typeid, &basetypesize)))
274 fv_vlen->
len = in_vlen->
len;
275 if (!(fv_vlen->p = malloc(basetypesize * in_vlen->
len)))
281 memcpy(fv_vlen->p, in_vlen->
p, in_vlen->
len * basetypesize);
283 else if (var->type_info->nc_type_class ==
NC_STRING)
285 if (*(
char **)var->fill_value)
286 if (!(**(
char ***)fillp = strdup(*(
char **)var->fill_value)))
294 memcpy((*fillp), var->fill_value, size);
298 if (nc4_get_default_fill_value(var->type_info, *fillp))
327 nc4_get_hdf_typeid(NC_FILE_INFO_T *h5,
nc_type xtype,
328 hid_t *hdf_typeid,
int endianness)
330 NC_TYPE_INFO_T *type;
334 assert(hdf_typeid && h5);
346 if ((
typeid = H5Tcopy(H5T_C_S1)) < 0)
348 if (H5Tset_strpad(
typeid, H5T_STR_NULLTERM) < 0)
350 if(H5Tset_cset(
typeid, H5T_CSET_ASCII) < 0)
354 *hdf_typeid =
typeid;
359 if ((
typeid = H5Tcopy(H5T_C_S1)) < 0)
361 if (H5Tset_size(
typeid, H5T_VARIABLE) < 0)
363 if(H5Tset_cset(
typeid, H5T_CSET_UTF8) < 0)
367 *hdf_typeid =
typeid;
378 typeid = H5T_STD_I8LE;
380 typeid = H5T_STD_I8BE;
382 typeid = H5T_NATIVE_SCHAR;
387 typeid = H5T_STD_I16LE;
389 typeid = H5T_STD_I16BE;
391 typeid = H5T_NATIVE_SHORT;
396 typeid = H5T_STD_I32LE;
398 typeid = H5T_STD_I32BE;
400 typeid = H5T_NATIVE_INT;
405 typeid = H5T_STD_U8LE;
407 typeid = H5T_STD_U8BE;
409 typeid = H5T_NATIVE_UCHAR;
414 typeid = H5T_STD_U16LE;
416 typeid = H5T_STD_U16BE;
418 typeid = H5T_NATIVE_USHORT;
423 typeid = H5T_STD_U32LE;
425 typeid = H5T_STD_U32BE;
427 typeid = H5T_NATIVE_UINT;
432 typeid = H5T_STD_I64LE;
434 typeid = H5T_STD_I64BE;
436 typeid = H5T_NATIVE_LLONG;
441 typeid = H5T_STD_U64LE;
443 typeid = H5T_STD_U64BE;
445 typeid = H5T_NATIVE_ULLONG;
450 typeid = H5T_IEEE_F32LE;
452 typeid = H5T_IEEE_F32BE;
454 typeid = H5T_NATIVE_FLOAT;
459 typeid = H5T_IEEE_F64LE;
461 typeid = H5T_IEEE_F64BE;
463 typeid = H5T_NATIVE_DOUBLE;
468 if (nc4_find_type(h5, xtype, &type))
472 typeid = ((NC_HDF5_TYPE_INFO_T *)type->format_type_info)->hdf_typeid;
478 if ((*hdf_typeid = H5Tcopy(
typeid)) < 0)
482 assert(*hdf_typeid != -1);
485 if (
typeid > 0 && H5Tclose(
typeid) < 0)
505 put_att_grpa(NC_GRP_INFO_T *grp,
int varid, NC_ATT_INFO_T *att)
507 NC_HDF5_GRP_INFO_T *hdf5_grp;
508 hid_t datasetid = 0, locid;
509 hid_t attid = 0, spaceid = 0, file_typeid = 0;
510 hid_t existing_att_typeid = 0, existing_attid = 0, existing_spaceid = 0;
514 int phoney_data = 99;
517 assert(att->hdr.name && grp && grp->format_grp_info);
518 LOG((3,
"%s: varid %d att->hdr.id %d att->hdr.name %s att->nc_typeid %d "
519 "att->len %d", __func__, varid, att->hdr.id, att->hdr.name,
520 att->nc_typeid, att->len));
523 hdf5_grp = (NC_HDF5_GRP_INFO_T *)grp->format_grp_info;
526 if (grp->nc4_info->no_write)
531 locid = hdf5_grp->hdf_grpid;
534 if ((retval = nc4_open_var_grp2(grp, varid, &datasetid)))
542 if ((retval = nc4_get_hdf_typeid(grp->nc4_info, att->nc_typeid,
553 else if (att->stdata)
565 size_t string_size = dims[0];
569 if ((spaceid = H5Screate(H5S_NULL)) < 0)
574 if ((spaceid = H5Screate(H5S_SCALAR)) < 0)
577 if (H5Tset_size(file_typeid, string_size) < 0)
579 if (H5Tset_strpad(file_typeid, H5T_STR_NULLTERM) < 0)
586 if ((spaceid = H5Screate(H5S_NULL)) < 0)
591 if ((spaceid = H5Screate_simple(1, dims, NULL)) < 0)
597 if ((attr_exists = H5Aexists(locid, att->hdr.name)) < 0)
604 if ((existing_attid = H5Aopen(locid, att->hdr.name, H5P_DEFAULT)) < 0)
608 if ((existing_att_typeid = H5Aget_type(existing_attid)) < 0)
612 if ((existing_spaceid = H5Aget_space(existing_attid)) < 0)
614 if ((npoints = H5Sget_simple_extent_npoints(existing_spaceid)) < 0)
619 if (!H5Tequal(file_typeid, existing_att_typeid) ||
620 (att->nc_typeid !=
NC_CHAR && npoints != att->len))
625 if (H5Adelete(locid, att->hdr.name) < 0)
630 if ((attid = H5Acreate(locid, att->hdr.name, file_typeid, spaceid,
635 if (H5Awrite(attid, file_typeid, data) < 0)
643 if (H5Awrite(existing_attid, file_typeid, data) < 0)
652 if ((attid = H5Acreate(locid, att->hdr.name, file_typeid, spaceid,
657 if (H5Awrite(attid, file_typeid, data) < 0)
662 if (file_typeid && H5Tclose(file_typeid))
664 if (attid > 0 && H5Aclose(attid) < 0)
666 if (existing_att_typeid && H5Tclose(existing_att_typeid))
668 if (existing_attid > 0 && H5Aclose(existing_attid) < 0)
670 if (spaceid > 0 && H5Sclose(spaceid) < 0)
672 if (existing_spaceid > 0 && H5Sclose(existing_spaceid) < 0)
689 write_attlist(NCindex *attlist,
int varid, NC_GRP_INFO_T *grp)
695 for(i = 0; i < ncindexsize(attlist); i++)
697 att = (NC_ATT_INFO_T *)ncindexith(attlist, i);
701 LOG((4,
"%s: writing att %s to varid %d", __func__, att->hdr.name, varid));
702 if ((retval = put_att_grpa(grp, varid, att)))
704 att->dirty = NC_FALSE;
705 att->created = NC_TRUE;
725 write_coord_dimids(NC_VAR_INFO_T *var)
727 NC_HDF5_VAR_INFO_T *hdf5_var;
728 hsize_t coords_len[1];
729 hid_t c_spaceid = -1, c_attid = -1;
732 assert(var && var->format_var_info);
735 hdf5_var = (NC_HDF5_VAR_INFO_T *)var->format_var_info;
738 coords_len[0] = var->ndims;
739 if ((c_spaceid = H5Screate_simple(1, coords_len, coords_len)) < 0)
743 if ((c_attid = H5Acreate(hdf5_var->hdf_datasetid, COORDINATES,
744 H5T_NATIVE_INT, c_spaceid, H5P_DEFAULT)) < 0)
748 if (H5Awrite(c_attid, H5T_NATIVE_INT, var->dimids) < 0)
752 if (c_spaceid >= 0 && H5Sclose(c_spaceid) < 0)
754 if (c_attid >= 0 && H5Aclose(c_attid) < 0)
770 write_netcdf4_dimid(hid_t datasetid,
int dimid)
772 hid_t dimid_spaceid = -1, dimid_attid = -1;
777 if ((dimid_spaceid = H5Screate(H5S_SCALAR)) < 0)
781 if ((attr_exists = H5Aexists(datasetid, NC_DIMID_ATT_NAME)) < 0)
784 dimid_attid = H5Aopen_by_name(datasetid,
".", NC_DIMID_ATT_NAME,
785 H5P_DEFAULT, H5P_DEFAULT);
788 dimid_attid = H5Acreate(datasetid, NC_DIMID_ATT_NAME,
789 H5T_NATIVE_INT, dimid_spaceid, H5P_DEFAULT);
795 LOG((4,
"%s: writing secret dimid %d", __func__, dimid));
796 if (H5Awrite(dimid_attid, H5T_NATIVE_INT, &dimid) < 0)
801 if (dimid_spaceid >= 0 && H5Sclose(dimid_spaceid) < 0)
803 if (dimid_attid >= 0 && H5Aclose(dimid_attid) < 0)
824 var_create_dataset(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var, nc_bool_t write_dimid)
826 NC_HDF5_GRP_INFO_T *hdf5_grp;
827 NC_HDF5_VAR_INFO_T *hdf5_var;
828 hid_t plistid = 0, access_plistid = 0,
typeid = 0, spaceid = 0;
829 hsize_t chunksize[H5S_MAX_RANK], dimsize[H5S_MAX_RANK], maxdimsize[H5S_MAX_RANK];
832 NC_DIM_INFO_T *dim = NULL;
836 assert(grp && grp->format_grp_info && var && var->format_var_info);
838 LOG((3,
"%s:: name %s", __func__, var->hdr.name));
841 hdf5_grp = (NC_HDF5_GRP_INFO_T *)grp->format_grp_info;
842 hdf5_var = (NC_HDF5_VAR_INFO_T *)var->format_var_info;
845 if ((plistid = H5Pcreate(H5P_DATASET_CREATE)) < 0)
847 if ((access_plistid = H5Pcreate(H5P_DATASET_ACCESS)) < 0)
851 if (H5Pset_obj_track_times(plistid, 0) < 0)
855 if ((retval = nc4_get_hdf_typeid(grp->nc4_info, var->type_info->hdr.id, &
typeid,
856 var->type_info->endianness)))
863 if (H5Pset_fill_time(plistid, H5D_FILL_TIME_NEVER) < 0)
868 if ((retval = nc4_get_fill_value(grp->nc4_info, var, &fillp)))
874 if (var->type_info->nc_type_class ==
NC_STRING)
876 if (H5Pset_fill_value(plistid,
typeid, fillp) < 0)
885 hid_t fill_typeid = 0;
887 if ((retval = nc4_get_hdf_typeid(grp->nc4_info, var->type_info->hdr.id, &fill_typeid,
890 if (H5Pset_fill_value(plistid, fill_typeid, fillp) < 0)
892 if (H5Tclose(fill_typeid) < 0)
896 if (H5Tclose(fill_typeid) < 0)
904 if (H5Pset_shuffle(plistid) < 0)
914 if(var->filters != NULL) {
916 for(j=0;j<nclistlength(var->filters);j++) {
917 NC_FILTER_SPEC_HDF5* fi = (NC_FILTER_SPEC_HDF5*)nclistget(var->filters,j);
919 unsigned int* params;
920 nparams = fi->nparams;
922 if(fi->filterid == H5Z_FILTER_DEFLATE) {
926 level = (int)params[0];
927 if(H5Pset_deflate(plistid, level) < 0)
929 }
else if(fi->filterid == H5Z_FILTER_SZIP) {
934 options_mask = (int)params[0];
935 bits_per_pixel = (int)params[1];
936 if(H5Pset_szip(plistid, options_mask, bits_per_pixel) < 0)
939 herr_t code = H5Pset_filter(plistid, (
unsigned int)fi->filterid, H5Z_FLAG_MANDATORY, nparams, params);
949 if (H5Pset_fletcher32(plistid) < 0)
961 for (d = 0; d < var->ndims; d++) {
963 assert(dim && dim->hdr.id == var->dimids[d]);
971 if (!var->shuffle && !var->fletcher32 && nclistlength(var->filters) == 0 &&
972 (var->chunksizes == NULL || !var->chunksizes[0]) && !unlimdim)
977 for (d = 0; d < var->ndims; d++)
980 assert(dim && dim->hdr.id == var->dimids[d]);
981 dimsize[d] = dim->unlimited ? NC_HDF5_UNLIMITED_DIMSIZE : dim->len;
982 maxdimsize[d] = dim->unlimited ? H5S_UNLIMITED : (hsize_t)dim->len;
985 if (var->chunksizes[d])
986 chunksize[d] = var->chunksizes[d];
990 if (var->type_info->nc_type_class ==
NC_STRING)
991 type_size =
sizeof(
char *);
993 type_size = var->type_info->size;
999 chunksize[d] = pow((
double)DEFAULT_CHUNK_SIZE/type_size,
1000 1/(
double)(var->ndims - unlimdim));
1004 if (!dim->unlimited && chunksize[d] > dim->len)
1005 chunksize[d] = dim->len;
1008 var->chunksizes[d] = chunksize[d];
1014 if ((spaceid = H5Screate_simple(var->ndims, dimsize, maxdimsize)) < 0)
1019 if ((spaceid = H5Screate(H5S_SCALAR)) < 0)
1028 if (H5Pset_layout(plistid, H5D_CONTIGUOUS) < 0)
1033 if (H5Pset_layout(plistid, H5D_COMPACT) < 0)
1036 else if (var->ndims)
1038 if (H5Pset_chunk(plistid, var->ndims, chunksize) < 0)
1043 if (H5Pset_attr_creation_order(plistid, H5P_CRT_ORDER_TRACKED|
1044 H5P_CRT_ORDER_INDEXED) < 0)
1048 if (var->storage ==
NC_CHUNKED && var->chunk_cache_size)
1049 if (H5Pset_chunk_cache(access_plistid, var->chunk_cache_nelems,
1050 var->chunk_cache_size, var->chunk_cache_preemption) < 0)
1054 name_to_use = var->hdf5_name ? var->hdf5_name : var->hdr.name;
1055 LOG((4,
"%s: about to H5Dcreate2 dataset %s of type 0x%x", __func__,
1056 name_to_use,
typeid));
1057 if ((hdf5_var->hdf_datasetid = H5Dcreate2(hdf5_grp->hdf_grpid, name_to_use,
typeid,
1058 spaceid, H5P_DEFAULT, plistid, access_plistid)) < 0)
1060 var->created = NC_TRUE;
1061 var->is_new_var = NC_FALSE;
1067 if ((retval = write_coord_dimids(var)))
1075 if (H5DSset_scale(hdf5_var->hdf_datasetid, var->hdr.name) < 0)
1086 if ((retval = write_netcdf4_dimid(hdf5_var->hdf_datasetid, var->dimids[0])))
1091 if ((retval = write_attlist(var->att, var->hdr.id, grp)))
1093 var->attr_dirty = NC_FALSE;
1096 if (
typeid > 0 && H5Tclose(
typeid) < 0)
1098 if (plistid > 0 && H5Pclose(plistid) < 0)
1100 if (access_plistid > 0 && H5Pclose(access_plistid) < 0)
1102 if (spaceid > 0 && H5Sclose(spaceid) < 0)
1106 if (var->type_info->nc_type_class ==
NC_VLEN)
1108 else if (var->type_info->nc_type_class ==
NC_STRING && *(
char **)fillp)
1109 free(*(
char **)fillp);
1130 nc4_adjust_var_cache(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var)
1132 size_t chunk_size_bytes = 1;
1140 #ifdef USE_PARALLEL4
1142 if (grp->nc4_info->parallel)
1147 for (d = 0; d < var->ndims; d++)
1148 chunk_size_bytes *= var->chunksizes[d];
1149 if (var->type_info->size)
1150 chunk_size_bytes *= var->type_info->size;
1152 chunk_size_bytes *=
sizeof(
char *);
1157 if (var->chunk_cache_size == CHUNK_CACHE_SIZE)
1158 if (chunk_size_bytes > var->chunk_cache_size)
1160 var->chunk_cache_size = chunk_size_bytes * DEFAULT_CHUNKS_IN_CACHE;
1161 if (var->chunk_cache_size > MAX_DEFAULT_CACHE_SIZE)
1162 var->chunk_cache_size = MAX_DEFAULT_CACHE_SIZE;
1163 if ((retval = nc4_reopen_dataset(grp, var)))
1186 commit_type(NC_GRP_INFO_T *grp, NC_TYPE_INFO_T *type)
1188 NC_HDF5_GRP_INFO_T *hdf5_grp;
1189 NC_HDF5_TYPE_INFO_T *hdf5_type;
1190 hid_t base_hdf_typeid;
1193 assert(grp && grp->format_grp_info && type && type->format_type_info);
1196 hdf5_grp = (NC_HDF5_GRP_INFO_T *)grp->format_grp_info;
1197 hdf5_type = (NC_HDF5_TYPE_INFO_T *)type->format_type_info;
1200 if (type->committed)
1206 NC_FIELD_INFO_T *field;
1207 hid_t hdf_base_typeid, hdf_typeid;
1210 if ((hdf5_type->hdf_typeid = H5Tcreate(H5T_COMPOUND, type->size)) < 0)
1212 LOG((4,
"creating compound type %s hdf_typeid 0x%x", type->hdr.name,
1213 hdf5_type->hdf_typeid));
1215 for(i=0;i<nclistlength(type->u.c.field);i++)
1217 field = (NC_FIELD_INFO_T *)nclistget(type->u.c.field, i);
1219 if ((retval = nc4_get_hdf_typeid(grp->nc4_info, field->nc_typeid,
1220 &hdf_base_typeid, type->endianness)))
1229 for (d = 0; d < field->ndims; d++)
1230 dims[d] = field->dim_size[d];
1231 if ((hdf_typeid = H5Tarray_create(hdf_base_typeid, field->ndims,
1234 if (H5Tclose(hdf_base_typeid) < 0)
1238 if (H5Tclose(hdf_base_typeid) < 0)
1242 hdf_typeid = hdf_base_typeid;
1243 LOG((4,
"inserting field %s offset %d hdf_typeid 0x%x", field->hdr.name,
1244 field->offset, hdf_typeid));
1245 if (H5Tinsert(hdf5_type->hdf_typeid, field->hdr.name, field->offset,
1248 if (H5Tclose(hdf_typeid) < 0)
1252 else if (type->nc_type_class ==
NC_VLEN)
1255 if ((retval = nc4_get_hdf_typeid(grp->nc4_info, type->u.v.base_nc_typeid,
1256 &base_hdf_typeid, type->endianness)))
1260 if ((hdf5_type->hdf_typeid = H5Tvlen_create(base_hdf_typeid)) < 0)
1263 else if (type->nc_type_class ==
NC_OPAQUE)
1266 if ((hdf5_type->hdf_typeid = H5Tcreate(H5T_OPAQUE, type->size)) < 0)
1269 else if (type->nc_type_class ==
NC_ENUM)
1271 NC_ENUM_MEMBER_INFO_T *enum_m;
1274 if (nclistlength(type->u.e.enum_member) == 0)
1278 if ((retval = nc4_get_hdf_typeid(grp->nc4_info, type->u.e.base_nc_typeid,
1279 &base_hdf_typeid, type->endianness)))
1283 if ((hdf5_type->hdf_typeid = H5Tenum_create(base_hdf_typeid)) < 0)
1287 for(i=0;i<nclistlength(type->u.e.enum_member);i++) {
1288 enum_m = (NC_ENUM_MEMBER_INFO_T*)nclistget(type->u.e.enum_member,i);
1289 if (H5Tenum_insert(hdf5_type->hdf_typeid, enum_m->name, enum_m->value) < 0)
1295 LOG((0,
"Unknown class: %d", type->nc_type_class));
1300 if (H5Tcommit(hdf5_grp->hdf_grpid, type->hdr.name, hdf5_type->hdf_typeid) < 0)
1302 type->committed = NC_TRUE;
1303 LOG((4,
"just committed type %s, HDF typeid: 0x%x", type->hdr.name,
1304 hdf5_type->hdf_typeid));
1309 if ((hdf5_type->native_hdf_typeid = H5Tget_native_type(hdf5_type->hdf_typeid,
1310 H5T_DIR_DEFAULT)) < 0)
1327 write_nc3_strict_att(hid_t hdf_grpid)
1329 hid_t attid = 0, spaceid = 0;
1336 if ((attr_exists = H5Aexists(hdf_grpid, NC3_STRICT_ATT_NAME)) < 0)
1343 if ((spaceid = H5Screate(H5S_SCALAR)) < 0)
1345 if ((attid = H5Acreate(hdf_grpid, NC3_STRICT_ATT_NAME,
1346 H5T_NATIVE_INT, spaceid, H5P_DEFAULT)) < 0)
1348 if (H5Awrite(attid, H5T_NATIVE_INT, &one) < 0)
1352 if (spaceid > 0 && (H5Sclose(spaceid) < 0))
1354 if (attid > 0 && (H5Aclose(attid) < 0))
1372 create_group(NC_GRP_INFO_T *grp)
1374 NC_HDF5_GRP_INFO_T *hdf5_grp, *parent_hdf5_grp;
1378 assert(grp && grp->format_grp_info && grp->parent &&
1379 grp->parent->format_grp_info);
1382 hdf5_grp = (NC_HDF5_GRP_INFO_T *)grp->format_grp_info;
1383 parent_hdf5_grp = (NC_HDF5_GRP_INFO_T *)grp->parent->format_grp_info;
1384 assert(parent_hdf5_grp->hdf_grpid);
1388 if ((gcpl_id = H5Pcreate(H5P_GROUP_CREATE)) < 0)
1392 if (H5Pset_obj_track_times(gcpl_id, 0) < 0)
1396 if (H5Pset_link_creation_order(gcpl_id, H5P_CRT_ORDER_TRACKED|H5P_CRT_ORDER_INDEXED) < 0)
1400 if (H5Pset_attr_creation_order(gcpl_id, H5P_CRT_ORDER_TRACKED|H5P_CRT_ORDER_INDEXED) < 0)
1404 if ((hdf5_grp->hdf_grpid = H5Gcreate2(parent_hdf5_grp->hdf_grpid, grp->hdr.name,
1405 H5P_DEFAULT, gcpl_id, H5P_DEFAULT)) < 0)
1409 if (gcpl_id > -1 && H5Pclose(gcpl_id) < 0)
1412 if (hdf5_grp->hdf_grpid > 0 && H5Gclose(hdf5_grp->hdf_grpid) < 0)
1429 attach_dimscales(NC_GRP_INFO_T *grp)
1432 NC_HDF5_VAR_INFO_T *hdf5_var;
1436 for (v = 0; v < ncindexsize(grp->vars); v++)
1439 var = (NC_VAR_INFO_T *)ncindexith(grp->vars, v);
1440 assert(var && var->format_var_info);
1441 hdf5_var = (NC_HDF5_VAR_INFO_T *)var->format_var_info;
1449 for (d = 0; d < var->ndims; d++)
1452 if (var->dimscale_attached)
1454 if (!var->dimscale_attached[d])
1457 assert(var->dim[d] && var->dim[d]->hdr.id == var->dimids[d] &&
1458 var->dim[d]->format_dim_info);
1460 LOG((2,
"%s: attaching scale for dimid %d to var %s",
1461 __func__, var->dimids[d], var->hdr.name));
1464 if (var->dim[d]->coord_var)
1465 dsid = ((NC_HDF5_VAR_INFO_T *)(var->dim[d]->coord_var->format_var_info))->hdf_datasetid;
1467 dsid = ((NC_HDF5_DIM_INFO_T *)var->dim[d]->format_dim_info)->hdf_dimscaleid;
1471 if (H5DSattach_scale(hdf5_var->hdf_datasetid, dsid, d) < 0)
1473 var->dimscale_attached[d] = NC_TRUE;
1493 var_exists(hid_t grpid,
char *name, nc_bool_t *exists)
1501 if ((link_exists = H5Lexists(grpid, name, H5P_DEFAULT)) < 0)
1508 if (H5Gget_objinfo(grpid, name, 1, &statbuf) < 0)
1511 if (H5G_DATASET == statbuf.type)
1534 remove_coord_atts(hid_t hdf_datasetid)
1540 if ((attr_exists = H5Aexists(hdf_datasetid, NC_DIMID_ATT_NAME)) < 0)
1544 if (H5Adelete(hdf_datasetid, NC_DIMID_ATT_NAME) < 0)
1549 if ((attr_exists = H5Aexists(hdf_datasetid,
1550 HDF5_DIMSCALE_CLASS_ATT_NAME)) < 0)
1554 if (H5Adelete(hdf_datasetid, HDF5_DIMSCALE_CLASS_ATT_NAME) < 0)
1557 if ((attr_exists = H5Aexists(hdf_datasetid,
1558 HDF5_DIMSCALE_NAME_ATT_NAME)) < 0)
1562 if (H5Adelete(hdf_datasetid, HDF5_DIMSCALE_NAME_ATT_NAME) < 0)
1583 write_var(NC_VAR_INFO_T *var, NC_GRP_INFO_T *grp, nc_bool_t write_dimid)
1585 NC_HDF5_GRP_INFO_T *hdf5_grp;
1586 NC_HDF5_VAR_INFO_T *hdf5_var;
1587 nc_bool_t replace_existing_var = NC_FALSE;
1590 assert(var && var->format_var_info && grp && grp->format_grp_info);
1592 LOG((4,
"%s: writing var %s", __func__, var->hdr.name));
1595 hdf5_grp = (NC_HDF5_GRP_INFO_T *)grp->format_grp_info;
1596 hdf5_var = (NC_HDF5_VAR_INFO_T *)var->format_var_info;
1600 if (var->created && var->fill_val_changed)
1602 replace_existing_var = NC_TRUE;
1603 var->fill_val_changed = NC_FALSE;
1609 flag_atts_dirty(var->att);
1616 if (var->became_coord_var)
1618 if ((NC_DIM_INFO_T *)ncindexlookup(grp->dim, var->hdr.name))
1622 if ((retval = var_exists(hdf5_grp->hdf_grpid, var->hdr.name, &exists)))
1628 replace_existing_var = NC_TRUE;
1629 flag_atts_dirty(var->att);
1636 if (replace_existing_var)
1641 if ((d1 = (NC_DIM_INFO_T *)ncindexlookup(grp->dim, var->hdr.name)))
1644 assert(d1->format_dim_info && d1->hdr.name);
1646 if ((retval = var_exists(hdf5_grp->hdf_grpid, var->hdr.name, &exists)))
1654 dsid = ((NC_HDF5_VAR_INFO_T *)d1->coord_var->format_var_info)->hdf_datasetid;
1656 dsid = ((NC_HDF5_DIM_INFO_T *)d1->format_dim_info)->hdf_dimscaleid;
1662 if ((retval = rec_detach_scales(grp->nc4_info->root_grp,
1663 var->dimids[0], dsid)))
1671 if (var->was_coord_var && var->dimscale_attached)
1678 if ((retval = remove_coord_atts(hdf5_var->hdf_datasetid)))
1682 for (d = 0; d < var->ndims; d++)
1684 if (var->dimscale_attached[d])
1687 assert(var->dim[d] && var->dim[d]->hdr.id == var->dimids[d] &&
1688 var->dim[d]->format_dim_info);
1691 if (var->dim[d]->coord_var)
1692 dsid = ((NC_HDF5_VAR_INFO_T *)var->dim[d]->coord_var->format_var_info)->hdf_datasetid;
1694 dsid = ((NC_HDF5_DIM_INFO_T *)var->dim[d]->format_dim_info)->hdf_dimscaleid;
1698 if (H5DSdetach_scale(hdf5_var->hdf_datasetid, dsid, d) < 0)
1700 var->dimscale_attached[d] = NC_FALSE;
1706 if (replace_existing_var)
1709 if (hdf5_var->hdf_datasetid && H5Dclose(hdf5_var->hdf_datasetid) < 0)
1711 hdf5_var->hdf_datasetid = 0;
1714 if (H5Gunlink(hdf5_grp->hdf_grpid, var->hdr.name) < 0)
1719 if (var->is_new_var || replace_existing_var)
1721 if ((retval = var_create_dataset(grp, var, write_dimid)))
1726 if (write_dimid && var->ndims)
1727 if ((retval = write_netcdf4_dimid(hdf5_var->hdf_datasetid,
1732 if (replace_existing_var)
1738 if ((retval = rec_reattach_scales(grp->nc4_info->root_grp,
1739 var->dimids[0], hdf5_var->hdf_datasetid)))
1746 if (var->dimscale_attached)
1747 memset(var->dimscale_attached, 0,
sizeof(nc_bool_t) * var->ndims);
1752 var->was_coord_var = NC_FALSE;
1753 var->became_coord_var = NC_FALSE;
1756 if (var->attr_dirty)
1759 if ((retval = write_attlist(var->att, var->hdr.id, grp)))
1761 var->attr_dirty = NC_FALSE;
1781 nc4_create_dim_wo_var(NC_DIM_INFO_T *dim)
1783 NC_HDF5_DIM_INFO_T *hdf5_dim;
1784 NC_HDF5_GRP_INFO_T *hdf5_grp;
1785 hid_t spaceid = -1, create_propid = -1;
1786 hsize_t dims[1], max_dims[1], chunk_dims[1] = {1};
1790 LOG((4,
"%s: creating dim %s", __func__, dim->hdr.name));
1793 assert(!dim->coord_var);
1796 hdf5_grp = (NC_HDF5_GRP_INFO_T *)dim->container->format_grp_info;
1797 hdf5_dim = (NC_HDF5_DIM_INFO_T *)dim->format_dim_info;
1800 if ((create_propid = H5Pcreate(H5P_DATASET_CREATE)) < 0)
1804 if (H5Pset_obj_track_times(create_propid, 0) < 0)
1809 max_dims[0] = dim->len;
1815 max_dims[0] = H5S_UNLIMITED;
1816 if (H5Pset_chunk(create_propid, 1, chunk_dims) < 0)
1821 if ((spaceid = H5Screate_simple(1, dims, max_dims)) < 0)
1825 if (H5Pset_attr_creation_order(create_propid, H5P_CRT_ORDER_TRACKED|
1826 H5P_CRT_ORDER_INDEXED) < 0)
1830 LOG((4,
"%s: about to H5Dcreate1 a dimscale dataset %s", __func__,
1832 if ((hdf5_dim->hdf_dimscaleid = H5Dcreate2(hdf5_grp->hdf_grpid, dim->hdr.name,
1833 H5T_IEEE_F32BE, spaceid,
1834 H5P_DEFAULT, create_propid,
1841 sprintf(dimscale_wo_var,
"%s%10d", DIM_WITHOUT_VARIABLE, (
int)dim->len);
1842 if (H5DSset_scale(hdf5_dim->hdf_dimscaleid, dimscale_wo_var) < 0)
1848 if ((retval = write_netcdf4_dimid(hdf5_dim->hdf_dimscaleid, dim->hdr.id)))
1852 if (spaceid > 0 && H5Sclose(spaceid) < 0)
1854 if (create_propid > 0 && H5Pclose(create_propid) < 0)
1872 write_dim(NC_DIM_INFO_T *dim, NC_GRP_INFO_T *grp, nc_bool_t write_dimid)
1874 NC_HDF5_DIM_INFO_T *hdf5_dim;
1877 assert(dim && dim->format_dim_info && grp && grp->format_grp_info);
1880 hdf5_dim = (NC_HDF5_DIM_INFO_T *)dim->format_dim_info;
1886 if (!hdf5_dim->hdf_dimscaleid)
1887 if ((retval = nc4_create_dim_wo_var(dim)))
1893 NC_VAR_INFO_T *v1 = NULL;
1895 assert(dim->unlimited);
1899 v1 = dim->coord_var;
1902 NC_HDF5_VAR_INFO_T *hdf5_v1;
1906 hdf5_v1 = (NC_HDF5_VAR_INFO_T *)v1->format_var_info;
1910 if (!(new_size = malloc(v1->ndims *
sizeof(hsize_t))))
1912 for (d1 = 0; d1 < v1->ndims; d1++)
1914 assert(v1->dim[d1] && v1->dim[d1]->hdr.id == v1->dimids[d1]);
1915 new_size[d1] = v1->dim[d1]->len;
1917 if (H5Dset_extent(hdf5_v1->hdf_datasetid, new_size) < 0)
1927 if (write_dimid && hdf5_dim->hdf_dimscaleid)
1928 if ((retval = write_netcdf4_dimid(hdf5_dim->hdf_dimscaleid, dim->hdr.id)))
1949 nc4_rec_write_metadata(NC_GRP_INFO_T *grp, nc_bool_t bad_coord_order)
1951 NC_DIM_INFO_T *dim = NULL;
1952 NC_VAR_INFO_T *var = NULL;
1953 NC_GRP_INFO_T *child_grp = NULL;
1954 int coord_varid = -1;
1960 assert(grp && grp->hdr.name &&
1961 ((NC_HDF5_GRP_INFO_T *)(grp->format_grp_info))->hdf_grpid);
1962 LOG((3,
"%s: grp->hdr.name %s, bad_coord_order %d", __func__, grp->hdr.name,
1966 if ((retval = write_attlist(grp->att,
NC_GLOBAL, grp)))
1971 dim = (NC_DIM_INFO_T *)ncindexith(grp->dim, dim_index);
1972 var = (NC_VAR_INFO_T *)ncindexith(grp->vars, var_index);
1979 nc_bool_t found_coord, wrote_coord;
1983 for (found_coord = NC_FALSE; dim && !found_coord; )
1985 if (!dim->coord_var)
1987 if ((retval = write_dim(dim, grp, bad_coord_order)))
1992 coord_varid = dim->coord_var->hdr.id;
1993 found_coord = NC_TRUE;
1995 dim = (NC_DIM_INFO_T *)ncindexith(grp->dim, ++dim_index);
2000 for (wrote_coord = NC_FALSE; var && !wrote_coord; )
2002 if ((retval = write_var(var, grp, bad_coord_order)))
2004 if (found_coord && var->hdr.id == coord_varid)
2005 wrote_coord = NC_TRUE;
2006 var = (NC_VAR_INFO_T *)ncindexith(grp->vars, ++var_index);
2011 if ((retval = attach_dimscales(grp)))
2015 for (i = 0; i < ncindexsize(grp->children); i++)
2017 child_grp = (NC_GRP_INFO_T *)ncindexith(grp->children, i);
2019 if ((retval = nc4_rec_write_metadata(child_grp, bad_coord_order)))
2035 nc4_rec_write_groups_types(NC_GRP_INFO_T *grp)
2037 NC_GRP_INFO_T *child_grp;
2038 NC_HDF5_GRP_INFO_T *hdf5_grp;
2039 NC_TYPE_INFO_T *type;
2043 assert(grp && grp->hdr.name && grp->format_grp_info);
2044 LOG((3,
"%s: grp->hdr.name %s", __func__, grp->hdr.name));
2047 hdf5_grp = (NC_HDF5_GRP_INFO_T *)grp->format_grp_info;
2050 if (!hdf5_grp->hdf_grpid)
2051 if ((retval = create_group(grp)))
2057 if ((retval = write_nc3_strict_att(hdf5_grp->hdf_grpid)))
2061 for(i=0;i<ncindexsize(grp->type);i++) {
2062 type = (NC_TYPE_INFO_T *)ncindexith(grp->type, i);
2064 if ((retval = commit_type(grp, type)))
2069 for(i=0;i<ncindexsize(grp->children);i++) {
2070 if((child_grp = (NC_GRP_INFO_T*)ncindexith(grp->children,i)) == NULL)
continue;
2071 if ((retval = nc4_rec_write_groups_types(child_grp)))
2091 nc4_rec_match_dimscales(NC_GRP_INFO_T *grp)
2099 assert(grp && grp->hdr.name);
2100 LOG((4,
"%s: grp->hdr.name %s", __func__, grp->hdr.name));
2103 for (i = 0; i < ncindexsize(grp->children); i++)
2105 g = (NC_GRP_INFO_T*)ncindexith(grp->children, i);
2107 if ((retval = nc4_rec_match_dimscales(g)))
2113 for (i = 0; i < ncindexsize(grp->vars); i++)
2115 NC_HDF5_VAR_INFO_T *hdf5_var;
2120 var = (NC_VAR_INFO_T*)ncindexith(grp->vars, i);
2121 assert(var && var->format_var_info);
2122 hdf5_var = (NC_HDF5_VAR_INFO_T *)var->format_var_info;
2140 for (d = 0; d < ndims; d++)
2142 if (var->dim[d] == NULL) {
2143 nc4_find_dim(grp, var->dimids[d], &var->dim[d], NULL);
2155 if (hdf5_var->dimscale_hdf5_objids)
2157 for (d = 0; d < var->ndims; d++)
2159 nc_bool_t finished = NC_FALSE;
2160 LOG((5,
"%s: var %s has dimscale info...", __func__, var->hdr.name));
2163 for (g = grp; g && !finished; g = g->parent)
2166 for (j = 0; j < ncindexsize(g->dim); j++)
2169 NC_HDF5_DIM_INFO_T *hdf5_dim;
2170 dim = (NC_DIM_INFO_T *)ncindexith(g->dim, j);
2171 assert(dim && dim->format_dim_info);
2172 hdf5_dim = (NC_HDF5_DIM_INFO_T *)dim->format_dim_info;
2176 if (hdf5_var->dimscale_hdf5_objids[d].fileno[0] == hdf5_dim->hdf5_objid.fileno[0] &&
2177 hdf5_var->dimscale_hdf5_objids[d].objno[0] == hdf5_dim->hdf5_objid.objno[0] &&
2178 hdf5_var->dimscale_hdf5_objids[d].fileno[1] == hdf5_dim->hdf5_objid.fileno[1] &&
2179 hdf5_var->dimscale_hdf5_objids[d].objno[1] == hdf5_dim->hdf5_objid.objno[1])
2181 LOG((4,
"%s: for dimension %d, found dim %s", __func__,
2183 var->dimids[d] = dim->hdr.id;
2190 LOG((5,
"%s: dimid for this dimscale is %d", __func__,
2191 var->type_info->hdr.id));
2198 hsize_t *h5dimlen = NULL, *h5dimlenmax = NULL;
2202 if ((spaceid = H5Dget_space(hdf5_var->hdf_datasetid)) < 0)
2208 if (!(h5dimlen = malloc(var->ndims *
sizeof(hsize_t))))
2210 if (!(h5dimlenmax = malloc(var->ndims *
sizeof(hsize_t))))
2215 if ((dataset_ndims = H5Sget_simple_extent_dims(spaceid, h5dimlen,
2216 h5dimlenmax)) < 0) {
2221 if (dataset_ndims != var->ndims) {
2230 if (H5Sget_simple_extent_type(spaceid) != H5S_SCALAR)
2235 if (H5Sclose(spaceid) < 0) {
2244 for (d = 0; d < var->ndims; d++)
2249 for(match=-1,k=0;k<ncindexsize(grp->dim);k++) {
2250 if((dim = (NC_DIM_INFO_T*)ncindexith(grp->dim,k)) == NULL)
continue;
2251 if ((dim->len == h5dimlen[d]) &&
2252 ((h5dimlenmax[d] == H5S_UNLIMITED && dim->unlimited) ||
2253 (h5dimlenmax[d] != H5S_UNLIMITED && !dim->unlimited)))
2261 sprintf(phony_dim_name,
"phony_dim_%d", grp->nc4_info->next_dimid);
2262 LOG((3,
"%s: creating phony dim for var %s", __func__, var->hdr.name));
2263 if ((retval = nc4_dim_list_add(grp, phony_dim_name, h5dimlen[d], -1, &dim)))
2270 if (!(dim->format_dim_info = calloc(1,
sizeof(NC_HDF5_DIM_INFO_T))))
2272 if (h5dimlenmax[d] == H5S_UNLIMITED)
2273 dim->unlimited = NC_TRUE;
2277 var->dimids[d] = dim->hdr.id;
2304 nc4_get_typeclass(
const NC_FILE_INFO_T *h5,
nc_type xtype,
int *type_class)
2308 LOG((4,
"%s xtype: %d", __func__, xtype));
2348 NC_TYPE_INFO_T *type;
2351 if ((retval = nc4_find_type(h5, xtype, &type)))
2356 *type_class = type->nc_type_class;
2375 reportobject(
int uselog, hid_t
id,
unsigned int type)
2377 char name[NC_HDF5_MAX_NAME];
2379 const char*
typename = NULL;
2380 long long printid = (
long long)
id;
2382 len = H5Iget_name(
id, name, NC_HDF5_MAX_NAME);
2387 case H5F_OBJ_FILE:
typename =
"File";
break;
2388 case H5F_OBJ_DATASET:
typename =
"Dataset";
break;
2389 case H5F_OBJ_GROUP:
typename =
"Group";
break;
2390 case H5F_OBJ_DATATYPE:
typename =
"Datatype";
break;
2392 typename =
"Attribute";
2393 len = H5Aget_name(
id, NC_HDF5_MAX_NAME, name);
2394 if(len < 0) len = 0;
2397 default:
typename =
"<unknown>";
break;
2401 LOG((0,
"Type = %s(%lld) name='%s'",
typename,printid,name));
2405 fprintf(stderr,
"Type = %s(%lld) name='%s'",
typename,printid,name);
2421 reportopenobjectsT(
int uselog, hid_t fid,
int ntypes,
unsigned int* otypes)
2425 size_t maxobjs = -1;
2426 hid_t* idlist = NULL;
2431 LOG((0,
"\nReport: open objects on %lld",(
long long)fid));
2434 fprintf(stdout,
"\nReport: open objects on %lld\n",(
long long)fid);
2435 maxobjs = H5Fget_obj_count(fid,H5F_OBJ_ALL);
2436 if(idlist != NULL) free(idlist);
2437 idlist = (hid_t*)malloc(
sizeof(hid_t)*maxobjs);
2438 for(t=0;t<ntypes;t++) {
2439 unsigned int ot = otypes[t];
2440 ocount = H5Fget_obj_ids(fid,ot,maxobjs,idlist);
2441 for(i=0;i<ocount;i++) {
2442 hid_t o = idlist[i];
2443 reportobject(uselog,o,ot);
2446 if(idlist != NULL) free(idlist);
2458 reportopenobjects(
int uselog, hid_t fid)
2460 unsigned int OTYPES[5] = {H5F_OBJ_FILE, H5F_OBJ_DATASET, H5F_OBJ_GROUP,
2461 H5F_OBJ_DATATYPE, H5F_OBJ_ATTR};
2463 reportopenobjectsT(uselog, fid ,5, OTYPES);
2474 showopenobjects5(NC_FILE_INFO_T* h5)
2476 NC_HDF5_FILE_INFO_T *hdf5_info;
2478 assert(h5 && h5->format_file_info);
2479 hdf5_info = (NC_HDF5_FILE_INFO_T *)h5->format_file_info;
2481 fprintf(stderr,
"===== begin showopenobjects =====\n");
2482 reportopenobjects(0,hdf5_info->hdfid);
2483 fprintf(stderr,
"===== end showopenobjects =====\n");
2496 showopenobjects(
int ncid)
2498 NC_FILE_INFO_T* h5 = NULL;
2501 if (nc4_find_nc_grp_h5(ncid, NULL, NULL, &h5) !=
NC_NOERR)
2502 fprintf(stderr,
"failed\n");
2504 showopenobjects5(h5);
2520 NC4_hdf5get_libversion(
unsigned* major,
unsigned* minor,
unsigned* release)
2522 if(H5get_libversion(major,minor,release) < 0)
2538 NC4_hdf5get_superblock(
struct NC_FILE_INFO* h5,
int* idp)
2540 NC_HDF5_FILE_INFO_T *hdf5_info;
2545 assert(h5 && h5->format_file_info);
2546 hdf5_info = (NC_HDF5_FILE_INFO_T *)h5->format_file_info;
2548 if((plist = H5Fget_create_plist(hdf5_info->hdfid)) < 0)
2550 if(H5Pget_version(plist, &super, NULL, NULL, NULL) < 0)
2552 if(idp) *idp = (int)super;
2554 if(plist >= 0) H5Pclose(plist);
2558 static int NC4_strict_att_exists(NC_FILE_INFO_T*);
2559 static int NC4_walk(hid_t,
int*);
2586 NC4_isnetcdf4(
struct NC_FILE_INFO* h5)
2594 exists = NC4_strict_att_exists(h5);
2600 stat = NC4_walk(((NC_HDF5_GRP_INFO_T *)(h5->root_grp->format_grp_info))->hdf_grpid,
2605 isnc4 = (count >= 2);
2620 NC4_strict_att_exists(NC_FILE_INFO_T *h5)
2626 grpid = ((NC_HDF5_GRP_INFO_T *)(h5->root_grp->format_grp_info))->hdf_grpid;
2629 if ((attr_exists = H5Aexists(grpid, NC3_STRICT_ATT_NAME)) < 0)
2631 return (attr_exists?1:0);
2644 NC4_walk(hid_t gid,
int* countp)
2653 char name[NC_HDF5_MAX_NAME];
2656 err = H5Gget_num_objs(gid, &nobj);
2657 if(err < 0)
return err;
2659 for(i = 0; i < nobj; i++) {
2661 len = H5Gget_objname_by_idx(gid,(hsize_t)i,name,(
size_t)NC_HDF5_MAX_NAME);
2662 if(len < 0)
return len;
2664 otype = H5Gget_objtype_by_idx(gid,(
size_t)i);
2667 grpid = H5Gopen(gid,name);
2668 NC4_walk(grpid,countp);
2673 if(strcmp(name,
"phony_dim")==0)
2674 *countp = *countp + 1;
2675 dsid = H5Dopen(gid,name);
2676 na = H5Aget_num_attrs(dsid);
2677 for(j = 0; j < na; j++) {
2678 hid_t aid = H5Aopen_idx(dsid,(
unsigned int) j);
2680 const NC_reservedatt* ra;
2681 ssize_t len = H5Aget_name(aid, NC_HDF5_MAX_NAME, name);
2682 if(len < 0)
return len;
2685 ra = NC_findreserved(name);
2687 *countp = *countp + 1;
2701 NC4_hdf5_remove_filter(NC_VAR_INFO_T* var,
unsigned int filterid)
2704 NC_HDF5_VAR_INFO_T *hdf5_var;
2709 hdf5_var = (NC_HDF5_VAR_INFO_T *)var->format_var_info;
2710 if ((propid = H5Dget_create_plist(hdf5_var->hdf_datasetid)) < 0)
2714 if((herr = H5Premove_filter(propid,hft)) < 0)
#define NC_ENOMEM
Memory allocation (malloc) failure.
#define NC_CHUNKED
In HDF5 files you can set storage for each variable to be either contiguous or chunked, with nc_def_var_chunking().
#define NC_CHAR
ISO/ASCII character.
#define NC_CONTIGUOUS
In HDF5 files you can set storage for each variable to be either contiguous or chunked, with nc_def_var_chunking().
#define NC_UBYTE
unsigned 1 byte int
#define NC_CLASSIC_MODEL
Enforce classic model on netCDF-4.
#define NC_MAX_VAR_DIMS
max per variable dimensions
#define NC_UINT
unsigned 4-byte int
#define NC_EHDFERR
Error at HDF5 layer.
#define NC_OPAQUE
opaque types
Main header file for the C API.
#define NC_INT64
signed 8-byte int
#define NC_DOUBLE
double precision floating point number
int nc_type
The nc_type type is just an int.
#define NC_BYTE
signed 1 byte integer
size_t len
Length of VL data (in base type units)
#define NC_ENDIAN_LITTLE
In HDF5 files you can set the endianness of variables with nc_def_var_endian().
#define NC_EATTMETA
Problem with attribute metadata.
#define NC_VLEN
vlen (variable-length) types
#define NC_EFILEMETA
Problem with file metadata.
#define NC_EFILTER
Filter operation failed.
#define NC_EBADTYPE
Not a netcdf data type.
#define NC_EDIMMETA
Problem with dimension metadata.
#define NC_EINVAL
Invalid Argument.
#define NC_INT
signed 4 byte integer
#define NC_ENDIAN_BIG
In HDF5 files you can set the endianness of variables with nc_def_var_endian().
#define NC_MAX_NAME
Maximum for classic library.
void * p
Pointer to VL data.
#define NC_NAT
Not A Type.
EXTERNL int nc_free_vlen(nc_vlen_t *vl)
Free memory in a VLEN object.
#define NC_USHORT
unsigned 2-byte int
#define NC_COMPACT
In HDF5 files you can set storage for each variable to be either contiguous or chunked, with nc_def_var_chunking().
#define NC_EVARMETA
Problem with variable metadata.
This is the type of arrays of vlens.
#define NC_SHORT
signed 2 byte integer
#define NC_ENDIAN_NATIVE
In HDF5 files you can set the endianness of variables with nc_def_var_endian().
#define NC_ENOTVAR
Variable not found.
#define NC_EPERM
Write to read only.
#define NC_NOERR
No Error.
#define NC_ENUM
enum types
#define NC_COMPOUND
compound types
#define NC_GLOBAL
Attribute id to put/get a global attribute.
#define NC_FLOAT
single precision floating point number
#define NC_UINT64
unsigned 8-byte int