18 #include "hdf5internal.h" 21 #ifdef HAVE_INTTYPES_H 22 #define __STDC_FORMAT_MACROS 26 #define NC_HDF5_MAX_NAME 1024 31 static NClist* filters = NULL;
42 flag_atts_dirty(NCindex *attlist) {
44 NC_ATT_INFO_T *att = NULL;
51 for(i=0;i<ncindexsize(attlist);i++) {
52 att = (NC_ATT_INFO_T*)ncindexith(attlist,i);
53 if(att == NULL)
continue;
77 rec_reattach_scales(NC_GRP_INFO_T *grp,
int dimid, hid_t dimscaleid)
80 NC_GRP_INFO_T *child_grp;
84 assert(grp && grp->hdr.name && dimid >= 0 && dimscaleid >= 0);
85 LOG((3,
"%s: grp->hdr.name %s", __func__, grp->hdr.name));
88 for (i = 0; i < ncindexsize(grp->children); i++)
90 child_grp = (NC_GRP_INFO_T*)ncindexith(grp->children, i);
92 if ((retval = rec_reattach_scales(child_grp, dimid, dimscaleid)))
97 for (i = 0; i < ncindexsize(grp->vars); i++)
99 NC_HDF5_VAR_INFO_T *hdf5_var;
101 var = (NC_VAR_INFO_T*)ncindexith(grp->vars,i);
102 assert(var && var->format_var_info);
103 hdf5_var = (NC_HDF5_VAR_INFO_T *)var->format_var_info;
105 for (d = 0; d < var->ndims; d++)
107 if (var->dimids[d] == dimid && !var->dimscale)
109 LOG((2,
"%s: attaching scale for dimid %d to var %s",
110 __func__, var->dimids[d], var->hdr.name));
113 if (H5DSattach_scale(hdf5_var->hdf_datasetid,
116 var->dimscale_attached[d] = NC_TRUE;
141 rec_detach_scales(NC_GRP_INFO_T *grp,
int dimid, hid_t dimscaleid)
144 NC_GRP_INFO_T *child_grp;
148 assert(grp && grp->hdr.name && dimid >= 0 && dimscaleid >= 0);
149 LOG((3,
"%s: grp->hdr.name %s", __func__, grp->hdr.name));
152 for(i=0;i<ncindexsize(grp->children);i++) {
153 child_grp = (NC_GRP_INFO_T*)ncindexith(grp->children,i);
154 if(child_grp == NULL)
continue;
155 if ((retval = rec_detach_scales(child_grp, dimid, dimscaleid)))
160 for (i = 0; i < ncindexsize(grp->vars); i++)
162 NC_HDF5_VAR_INFO_T *hdf5_var;
163 var = (NC_VAR_INFO_T*)ncindexith(grp->vars, i);
164 assert(var && var->format_var_info);
165 hdf5_var = (NC_HDF5_VAR_INFO_T *)var->format_var_info;
167 for (d = 0; d < var->ndims; d++)
169 if (var->dimids[d] == dimid && !var->dimscale)
171 LOG((2,
"%s: detaching scale for dimid %d to var %s",
172 __func__, var->dimids[d], var->hdr.name));
175 if (var->dimscale_attached && var->dimscale_attached[d])
177 if (H5DSdetach_scale(hdf5_var->hdf_datasetid,
180 var->dimscale_attached[d] = NC_FALSE;
201 nc4_open_var_grp2(NC_GRP_INFO_T *grp,
int varid, hid_t *dataset)
204 NC_HDF5_VAR_INFO_T *hdf5_var;
206 assert(grp && grp->format_grp_info && dataset);
209 if (!(var = (NC_VAR_INFO_T *)ncindexith(grp->vars, varid)))
211 assert(var && var->hdr.id == varid && var->format_var_info);
212 hdf5_var = (NC_HDF5_VAR_INFO_T *)var->format_var_info;
215 if (!hdf5_var->hdf_datasetid)
217 NC_HDF5_GRP_INFO_T *hdf5_grp;
218 hdf5_grp = (NC_HDF5_GRP_INFO_T *)grp->format_grp_info;
220 if ((hdf5_var->hdf_datasetid = H5Dopen2(hdf5_grp->hdf_grpid,
221 var->hdr.name, H5P_DEFAULT)) < 0)
225 *dataset = hdf5_var->hdf_datasetid;
242 nc4_get_fill_value(NC_FILE_INFO_T *h5, NC_VAR_INFO_T *var,
void **fillp)
248 if (var->type_info->nc_type_class ==
NC_VLEN)
250 else if (var->type_info->nc_type_class ==
NC_STRING)
251 size =
sizeof(
char *);
254 if ((retval = nc4_get_typelen_mem(h5, var->type_info->hdr.id, &size)))
260 if (!((*fillp) = calloc(1, size)))
267 LOG((4,
"Found a fill value for var %s", var->hdr.name));
268 if (var->type_info->nc_type_class ==
NC_VLEN)
271 size_t basetypesize = 0;
273 if((retval=nc4_get_typelen_mem(h5, var->type_info->u.v.base_nc_typeid, &basetypesize)))
276 fv_vlen->
len = in_vlen->
len;
277 if (!(fv_vlen->p = malloc(basetypesize * in_vlen->
len)))
283 memcpy(fv_vlen->p, in_vlen->
p, in_vlen->
len * basetypesize);
285 else if (var->type_info->nc_type_class ==
NC_STRING)
287 if (*(
char **)var->fill_value)
288 if (!(**(
char ***)fillp = strdup(*(
char **)var->fill_value)))
296 memcpy((*fillp), var->fill_value, size);
300 if (nc4_get_default_fill_value(var->type_info, *fillp))
329 nc4_get_hdf_typeid(NC_FILE_INFO_T *h5,
nc_type xtype,
330 hid_t *hdf_typeid,
int endianness)
332 NC_TYPE_INFO_T *type;
336 assert(hdf_typeid && h5);
348 if ((
typeid = H5Tcopy(H5T_C_S1)) < 0)
350 if (H5Tset_strpad(
typeid, H5T_STR_NULLTERM) < 0)
352 if(H5Tset_cset(
typeid, H5T_CSET_ASCII) < 0)
356 *hdf_typeid =
typeid;
361 if ((
typeid = H5Tcopy(H5T_C_S1)) < 0)
363 if (H5Tset_size(
typeid, H5T_VARIABLE) < 0)
365 if(H5Tset_cset(
typeid, H5T_CSET_UTF8) < 0)
369 *hdf_typeid =
typeid;
380 typeid = H5T_STD_I8LE;
382 typeid = H5T_STD_I8BE;
384 typeid = H5T_NATIVE_SCHAR;
389 typeid = H5T_STD_I16LE;
391 typeid = H5T_STD_I16BE;
393 typeid = H5T_NATIVE_SHORT;
398 typeid = H5T_STD_I32LE;
400 typeid = H5T_STD_I32BE;
402 typeid = H5T_NATIVE_INT;
407 typeid = H5T_STD_U8LE;
409 typeid = H5T_STD_U8BE;
411 typeid = H5T_NATIVE_UCHAR;
416 typeid = H5T_STD_U16LE;
418 typeid = H5T_STD_U16BE;
420 typeid = H5T_NATIVE_USHORT;
425 typeid = H5T_STD_U32LE;
427 typeid = H5T_STD_U32BE;
429 typeid = H5T_NATIVE_UINT;
434 typeid = H5T_STD_I64LE;
436 typeid = H5T_STD_I64BE;
438 typeid = H5T_NATIVE_LLONG;
443 typeid = H5T_STD_U64LE;
445 typeid = H5T_STD_U64BE;
447 typeid = H5T_NATIVE_ULLONG;
452 typeid = H5T_IEEE_F32LE;
454 typeid = H5T_IEEE_F32BE;
456 typeid = H5T_NATIVE_FLOAT;
461 typeid = H5T_IEEE_F64LE;
463 typeid = H5T_IEEE_F64BE;
465 typeid = H5T_NATIVE_DOUBLE;
470 if (nc4_find_type(h5, xtype, &type))
474 typeid = ((NC_HDF5_TYPE_INFO_T *)type->format_type_info)->hdf_typeid;
480 if ((*hdf_typeid = H5Tcopy(
typeid)) < 0)
484 assert(*hdf_typeid != -1);
487 if (
typeid > 0 && H5Tclose(
typeid) < 0)
507 put_att_grpa(NC_GRP_INFO_T *grp,
int varid, NC_ATT_INFO_T *att)
509 NC_HDF5_GRP_INFO_T *hdf5_grp;
510 hid_t datasetid = 0, locid;
511 hid_t attid = 0, spaceid = 0, file_typeid = 0;
512 hid_t existing_att_typeid = 0, existing_attid = 0, existing_spaceid = 0;
516 int phoney_data = 99;
519 assert(att->hdr.name && grp && grp->format_grp_info);
520 LOG((3,
"%s: varid %d att->hdr.id %d att->hdr.name %s att->nc_typeid %d " 521 "att->len %d", __func__, varid, att->hdr.id, att->hdr.name,
522 att->nc_typeid, att->len));
525 hdf5_grp = (NC_HDF5_GRP_INFO_T *)grp->format_grp_info;
528 if (grp->nc4_info->no_write)
533 locid = hdf5_grp->hdf_grpid;
536 if ((retval = nc4_open_var_grp2(grp, varid, &datasetid)))
544 if ((retval = nc4_get_hdf_typeid(grp->nc4_info, att->nc_typeid,
555 else if (att->stdata)
567 size_t string_size = dims[0];
571 if ((spaceid = H5Screate(H5S_NULL)) < 0)
576 if ((spaceid = H5Screate(H5S_SCALAR)) < 0)
579 if (H5Tset_size(file_typeid, string_size) < 0)
581 if (H5Tset_strpad(file_typeid, H5T_STR_NULLTERM) < 0)
588 if ((spaceid = H5Screate(H5S_NULL)) < 0)
593 if ((spaceid = H5Screate_simple(1, dims, NULL)) < 0)
599 if ((attr_exists = H5Aexists(locid, att->hdr.name)) < 0)
606 if ((existing_attid = H5Aopen(locid, att->hdr.name, H5P_DEFAULT)) < 0)
610 if ((existing_att_typeid = H5Aget_type(existing_attid)) < 0)
614 if ((existing_spaceid = H5Aget_space(existing_attid)) < 0)
616 if ((npoints = H5Sget_simple_extent_npoints(existing_spaceid)) < 0)
621 if (!H5Tequal(file_typeid, existing_att_typeid) ||
622 (att->nc_typeid !=
NC_CHAR && npoints != att->len))
627 if (H5Adelete(locid, att->hdr.name) < 0)
632 if ((attid = H5Acreate(locid, att->hdr.name, file_typeid, spaceid,
637 if (H5Awrite(attid, file_typeid, data) < 0)
645 if (H5Awrite(existing_attid, file_typeid, data) < 0)
654 if ((attid = H5Acreate(locid, att->hdr.name, file_typeid, spaceid,
659 if (H5Awrite(attid, file_typeid, data) < 0)
664 if (file_typeid && H5Tclose(file_typeid))
666 if (attid > 0 && H5Aclose(attid) < 0)
668 if (existing_att_typeid && H5Tclose(existing_att_typeid))
670 if (existing_attid > 0 && H5Aclose(existing_attid) < 0)
672 if (spaceid > 0 && H5Sclose(spaceid) < 0)
674 if (existing_spaceid > 0 && H5Sclose(existing_spaceid) < 0)
691 write_attlist(NCindex *attlist,
int varid, NC_GRP_INFO_T *grp)
697 for(i = 0; i < ncindexsize(attlist); i++)
699 att = (NC_ATT_INFO_T *)ncindexith(attlist, i);
703 LOG((4,
"%s: writing att %s to varid %d", __func__, att->hdr.name, varid));
704 if ((retval = put_att_grpa(grp, varid, att)))
706 att->dirty = NC_FALSE;
707 att->created = NC_TRUE;
727 write_coord_dimids(NC_VAR_INFO_T *var)
729 NC_HDF5_VAR_INFO_T *hdf5_var;
730 hsize_t coords_len[1];
731 hid_t c_spaceid = -1, c_attid = -1;
734 assert(var && var->format_var_info);
737 hdf5_var = (NC_HDF5_VAR_INFO_T *)var->format_var_info;
740 coords_len[0] = var->ndims;
741 if ((c_spaceid = H5Screate_simple(1, coords_len, coords_len)) < 0)
745 if ((c_attid = H5Acreate(hdf5_var->hdf_datasetid, COORDINATES,
746 H5T_NATIVE_INT, c_spaceid, H5P_DEFAULT)) < 0)
750 if (H5Awrite(c_attid, H5T_NATIVE_INT, var->dimids) < 0)
754 if (c_spaceid >= 0 && H5Sclose(c_spaceid) < 0)
756 if (c_attid >= 0 && H5Aclose(c_attid) < 0)
772 write_netcdf4_dimid(hid_t datasetid,
int dimid)
774 hid_t dimid_spaceid = -1, dimid_attid = -1;
779 if ((dimid_spaceid = H5Screate(H5S_SCALAR)) < 0)
783 if ((attr_exists = H5Aexists(datasetid, NC_DIMID_ATT_NAME)) < 0)
786 dimid_attid = H5Aopen_by_name(datasetid,
".", NC_DIMID_ATT_NAME,
787 H5P_DEFAULT, H5P_DEFAULT);
790 dimid_attid = H5Acreate(datasetid, NC_DIMID_ATT_NAME,
791 H5T_NATIVE_INT, dimid_spaceid, H5P_DEFAULT);
797 LOG((4,
"%s: writing secret dimid %d", __func__, dimid));
798 if (H5Awrite(dimid_attid, H5T_NATIVE_INT, &dimid) < 0)
803 if (dimid_spaceid >= 0 && H5Sclose(dimid_spaceid) < 0)
805 if (dimid_attid >= 0 && H5Aclose(dimid_attid) < 0)
826 var_create_dataset(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var, nc_bool_t write_dimid)
828 NC_HDF5_GRP_INFO_T *hdf5_grp;
829 NC_HDF5_VAR_INFO_T *hdf5_var;
830 hid_t plistid = 0, access_plistid = 0,
typeid = 0, spaceid = 0;
831 hsize_t chunksize[H5S_MAX_RANK], dimsize[H5S_MAX_RANK], maxdimsize[H5S_MAX_RANK];
834 NC_DIM_INFO_T *dim = NULL;
838 assert(grp && grp->format_grp_info && var && var->format_var_info);
840 LOG((3,
"%s:: name %s", __func__, var->hdr.name));
843 hdf5_grp = (NC_HDF5_GRP_INFO_T *)grp->format_grp_info;
844 hdf5_var = (NC_HDF5_VAR_INFO_T *)var->format_var_info;
847 if ((plistid = H5Pcreate(H5P_DATASET_CREATE)) < 0)
849 if ((access_plistid = H5Pcreate(H5P_DATASET_ACCESS)) < 0)
853 if (H5Pset_obj_track_times(plistid, 0) < 0)
857 if ((retval = nc4_get_hdf_typeid(grp->nc4_info, var->type_info->hdr.id, &
typeid,
858 var->type_info->endianness)))
865 if (H5Pset_fill_time(plistid, H5D_FILL_TIME_NEVER) < 0)
870 if ((retval = nc4_get_fill_value(grp->nc4_info, var, &fillp)))
876 if (var->type_info->nc_type_class ==
NC_STRING)
878 if (H5Pset_fill_value(plistid,
typeid, fillp) < 0)
887 hid_t fill_typeid = 0;
889 if ((retval = nc4_get_hdf_typeid(grp->nc4_info, var->type_info->hdr.id, &fill_typeid,
892 if (H5Pset_fill_value(plistid, fill_typeid, fillp) < 0)
894 if (H5Tclose(fill_typeid) < 0)
898 if (H5Tclose(fill_typeid) < 0)
906 if (H5Pset_shuffle(plistid) < 0)
912 if (H5Pset_deflate(plistid, var->deflate_level) < 0)
914 }
else if(var->filterid) {
919 if(var->nparams != 2)
921 options_mask = (int)var->params[0];
922 bits_per_pixel = (
int)var->params[1];
923 if(H5Pset_szip(plistid, options_mask, bits_per_pixel) < 0)
926 herr_t code = H5Pset_filter(plistid, var->filterid, H5Z_FLAG_MANDATORY, var->nparams, var->params);
935 if (H5Pset_fletcher32(plistid) < 0)
947 for (d = 0; d < var->ndims; d++) {
949 assert(dim && dim->hdr.id == var->dimids[d]);
957 if (!var->shuffle && !var->deflate && !var->fletcher32 &&
958 (var->chunksizes == NULL || !var->chunksizes[0]) && !unlimdim)
959 var->contiguous = NC_TRUE;
962 for (d = 0; d < var->ndims; d++)
965 assert(dim && dim->hdr.id == var->dimids[d]);
966 dimsize[d] = dim->unlimited ? NC_HDF5_UNLIMITED_DIMSIZE : dim->len;
967 maxdimsize[d] = dim->unlimited ? H5S_UNLIMITED : (hsize_t)dim->len;
968 if (!var->contiguous) {
969 if (var->chunksizes[d])
970 chunksize[d] = var->chunksizes[d];
974 if (var->type_info->nc_type_class ==
NC_STRING)
975 type_size =
sizeof(
char *);
977 type_size = var->type_info->size;
983 chunksize[d] = pow((
double)DEFAULT_CHUNK_SIZE/type_size,
984 1/(
double)(var->ndims - unlimdim));
988 if (!dim->unlimited && chunksize[d] > dim->len)
989 chunksize[d] = dim->len;
992 var->chunksizes[d] = chunksize[d];
999 if (H5Pset_layout(plistid, H5D_CONTIGUOUS) < 0)
1004 if (H5Pset_chunk(plistid, var->ndims, chunksize) < 0)
1009 if ((spaceid = H5Screate_simple(var->ndims, dimsize, maxdimsize)) < 0)
1014 if ((spaceid = H5Screate(H5S_SCALAR)) < 0)
1019 if (H5Pset_attr_creation_order(plistid, H5P_CRT_ORDER_TRACKED|
1020 H5P_CRT_ORDER_INDEXED) < 0)
1024 if (!var->contiguous && var->chunk_cache_size)
1025 if (H5Pset_chunk_cache(access_plistid, var->chunk_cache_nelems,
1026 var->chunk_cache_size, var->chunk_cache_preemption) < 0)
1030 name_to_use = var->hdf5_name ? var->hdf5_name : var->hdr.name;
1031 LOG((4,
"%s: about to H5Dcreate2 dataset %s of type 0x%x", __func__,
1032 name_to_use,
typeid));
1033 if ((hdf5_var->hdf_datasetid = H5Dcreate2(hdf5_grp->hdf_grpid, name_to_use,
typeid,
1034 spaceid, H5P_DEFAULT, plistid, access_plistid)) < 0)
1036 var->created = NC_TRUE;
1037 var->is_new_var = NC_FALSE;
1043 if ((retval = write_coord_dimids(var)))
1051 if (H5DSset_scale(hdf5_var->hdf_datasetid, var->hdr.name) < 0)
1062 if ((retval = write_netcdf4_dimid(hdf5_var->hdf_datasetid, var->dimids[0])))
1067 if ((retval = write_attlist(var->att, var->hdr.id, grp)))
1069 var->attr_dirty = NC_FALSE;
1072 if (
typeid > 0 && H5Tclose(
typeid) < 0)
1074 if (plistid > 0 && H5Pclose(plistid) < 0)
1076 if (access_plistid > 0 && H5Pclose(access_plistid) < 0)
1078 if (spaceid > 0 && H5Sclose(spaceid) < 0)
1082 if (var->type_info->nc_type_class ==
NC_VLEN)
1084 else if (var->type_info->nc_type_class ==
NC_STRING && *(
char **)fillp)
1085 free(*(
char **)fillp);
1103 nc4_adjust_var_cache(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var)
1105 size_t chunk_size_bytes = 1;
1110 if (var->contiguous)
1112 #ifdef USE_PARALLEL4 1117 for (d = 0; d < var->ndims; d++)
1118 chunk_size_bytes *= var->chunksizes[d];
1119 if (var->type_info->size)
1120 chunk_size_bytes *= var->type_info->size;
1122 chunk_size_bytes *=
sizeof(
char *);
1127 if (var->chunk_cache_size == CHUNK_CACHE_SIZE)
1128 if (chunk_size_bytes > var->chunk_cache_size)
1130 var->chunk_cache_size = chunk_size_bytes * DEFAULT_CHUNKS_IN_CACHE;
1131 if (var->chunk_cache_size > MAX_DEFAULT_CACHE_SIZE)
1132 var->chunk_cache_size = MAX_DEFAULT_CACHE_SIZE;
1133 if ((retval = nc4_reopen_dataset(grp, var)))
1156 commit_type(NC_GRP_INFO_T *grp, NC_TYPE_INFO_T *type)
1158 NC_HDF5_GRP_INFO_T *hdf5_grp;
1159 NC_HDF5_TYPE_INFO_T *hdf5_type;
1160 hid_t base_hdf_typeid;
1163 assert(grp && grp->format_grp_info && type && type->format_type_info);
1166 hdf5_grp = (NC_HDF5_GRP_INFO_T *)grp->format_grp_info;
1167 hdf5_type = (NC_HDF5_TYPE_INFO_T *)type->format_type_info;
1170 if (type->committed)
1176 NC_FIELD_INFO_T *field;
1177 hid_t hdf_base_typeid, hdf_typeid;
1180 if ((hdf5_type->hdf_typeid = H5Tcreate(H5T_COMPOUND, type->size)) < 0)
1182 LOG((4,
"creating compound type %s hdf_typeid 0x%x", type->hdr.name,
1183 hdf5_type->hdf_typeid));
1185 for(i=0;i<nclistlength(type->u.c.field);i++)
1187 field = (NC_FIELD_INFO_T *)nclistget(type->u.c.field, i);
1189 if ((retval = nc4_get_hdf_typeid(grp->nc4_info, field->nc_typeid,
1190 &hdf_base_typeid, type->endianness)))
1199 for (d = 0; d < field->ndims; d++)
1200 dims[d] = field->dim_size[d];
1201 if ((hdf_typeid = H5Tarray_create(hdf_base_typeid, field->ndims,
1204 if (H5Tclose(hdf_base_typeid) < 0)
1208 if (H5Tclose(hdf_base_typeid) < 0)
1212 hdf_typeid = hdf_base_typeid;
1213 LOG((4,
"inserting field %s offset %d hdf_typeid 0x%x", field->hdr.name,
1214 field->offset, hdf_typeid));
1215 if (H5Tinsert(hdf5_type->hdf_typeid, field->hdr.name, field->offset,
1218 if (H5Tclose(hdf_typeid) < 0)
1222 else if (type->nc_type_class ==
NC_VLEN)
1225 if ((retval = nc4_get_hdf_typeid(grp->nc4_info, type->u.v.base_nc_typeid,
1226 &base_hdf_typeid, type->endianness)))
1230 if ((hdf5_type->hdf_typeid = H5Tvlen_create(base_hdf_typeid)) < 0)
1233 else if (type->nc_type_class ==
NC_OPAQUE)
1236 if ((hdf5_type->hdf_typeid = H5Tcreate(H5T_OPAQUE, type->size)) < 0)
1239 else if (type->nc_type_class ==
NC_ENUM)
1241 NC_ENUM_MEMBER_INFO_T *enum_m;
1244 if (nclistlength(type->u.e.enum_member) == 0)
1248 if ((retval = nc4_get_hdf_typeid(grp->nc4_info, type->u.e.base_nc_typeid,
1249 &base_hdf_typeid, type->endianness)))
1253 if ((hdf5_type->hdf_typeid = H5Tenum_create(base_hdf_typeid)) < 0)
1257 for(i=0;i<nclistlength(type->u.e.enum_member);i++) {
1258 enum_m = (NC_ENUM_MEMBER_INFO_T*)nclistget(type->u.e.enum_member,i);
1259 if (H5Tenum_insert(hdf5_type->hdf_typeid, enum_m->name, enum_m->value) < 0)
1265 LOG((0,
"Unknown class: %d", type->nc_type_class));
1270 if (H5Tcommit(hdf5_grp->hdf_grpid, type->hdr.name, hdf5_type->hdf_typeid) < 0)
1272 type->committed = NC_TRUE;
1273 LOG((4,
"just committed type %s, HDF typeid: 0x%x", type->hdr.name,
1274 hdf5_type->hdf_typeid));
1279 if ((hdf5_type->native_hdf_typeid = H5Tget_native_type(hdf5_type->hdf_typeid,
1280 H5T_DIR_DEFAULT)) < 0)
1297 write_nc3_strict_att(hid_t hdf_grpid)
1299 hid_t attid = 0, spaceid = 0;
1306 if ((attr_exists = H5Aexists(hdf_grpid, NC3_STRICT_ATT_NAME)) < 0)
1313 if ((spaceid = H5Screate(H5S_SCALAR)) < 0)
1315 if ((attid = H5Acreate(hdf_grpid, NC3_STRICT_ATT_NAME,
1316 H5T_NATIVE_INT, spaceid, H5P_DEFAULT)) < 0)
1318 if (H5Awrite(attid, H5T_NATIVE_INT, &one) < 0)
1322 if (spaceid > 0 && (H5Sclose(spaceid) < 0))
1324 if (attid > 0 && (H5Aclose(attid) < 0))
1342 create_group(NC_GRP_INFO_T *grp)
1344 NC_HDF5_GRP_INFO_T *hdf5_grp, *parent_hdf5_grp;
1348 assert(grp && grp->format_grp_info && grp->parent &&
1349 grp->parent->format_grp_info);
1352 hdf5_grp = (NC_HDF5_GRP_INFO_T *)grp->format_grp_info;
1353 parent_hdf5_grp = (NC_HDF5_GRP_INFO_T *)grp->parent->format_grp_info;
1354 assert(parent_hdf5_grp->hdf_grpid);
1358 if ((gcpl_id = H5Pcreate(H5P_GROUP_CREATE)) < 0)
1362 if (H5Pset_obj_track_times(gcpl_id, 0) < 0)
1366 if (H5Pset_link_creation_order(gcpl_id, H5P_CRT_ORDER_TRACKED|H5P_CRT_ORDER_INDEXED) < 0)
1370 if (H5Pset_attr_creation_order(gcpl_id, H5P_CRT_ORDER_TRACKED|H5P_CRT_ORDER_INDEXED) < 0)
1374 if ((hdf5_grp->hdf_grpid = H5Gcreate2(parent_hdf5_grp->hdf_grpid, grp->hdr.name,
1375 H5P_DEFAULT, gcpl_id, H5P_DEFAULT)) < 0)
1379 if (gcpl_id > -1 && H5Pclose(gcpl_id) < 0)
1382 if (hdf5_grp->hdf_grpid > 0 && H5Gclose(hdf5_grp->hdf_grpid) < 0)
1399 attach_dimscales(NC_GRP_INFO_T *grp)
1402 NC_HDF5_VAR_INFO_T *hdf5_var;
1406 for (v = 0; v < ncindexsize(grp->vars); v++)
1409 var = (NC_VAR_INFO_T *)ncindexith(grp->vars, v);
1410 assert(var && var->format_var_info);
1411 hdf5_var = (NC_HDF5_VAR_INFO_T *)var->format_var_info;
1419 for (d = 0; d < var->ndims; d++)
1422 if (var->dimscale_attached)
1424 if (!var->dimscale_attached[d])
1427 assert(var->dim[d] && var->dim[d]->hdr.id == var->dimids[d] &&
1428 var->dim[d]->format_dim_info);
1430 LOG((2,
"%s: attaching scale for dimid %d to var %s",
1431 __func__, var->dimids[d], var->hdr.name));
1434 if (var->dim[d]->coord_var)
1435 dsid = ((NC_HDF5_VAR_INFO_T *)(var->dim[d]->coord_var->format_var_info))->hdf_datasetid;
1437 dsid = ((NC_HDF5_DIM_INFO_T *)var->dim[d]->format_dim_info)->hdf_dimscaleid;
1441 if (H5DSattach_scale(hdf5_var->hdf_datasetid, dsid, d) < 0)
1443 var->dimscale_attached[d] = NC_TRUE;
1463 var_exists(hid_t grpid,
char *name, nc_bool_t *exists)
1471 if ((link_exists = H5Lexists(grpid, name, H5P_DEFAULT)) < 0)
1478 if (H5Gget_objinfo(grpid, name, 1, &statbuf) < 0)
1481 if (H5G_DATASET == statbuf.type)
1504 remove_coord_atts(hid_t hdf_datasetid)
1510 if ((attr_exists = H5Aexists(hdf_datasetid, NC_DIMID_ATT_NAME)) < 0)
1514 if (H5Adelete(hdf_datasetid, NC_DIMID_ATT_NAME) < 0)
1519 if ((attr_exists = H5Aexists(hdf_datasetid,
1520 HDF5_DIMSCALE_CLASS_ATT_NAME)) < 0)
1524 if (H5Adelete(hdf_datasetid, HDF5_DIMSCALE_CLASS_ATT_NAME) < 0)
1527 if ((attr_exists = H5Aexists(hdf_datasetid,
1528 HDF5_DIMSCALE_NAME_ATT_NAME)) < 0)
1532 if (H5Adelete(hdf_datasetid, HDF5_DIMSCALE_NAME_ATT_NAME) < 0)
1553 write_var(NC_VAR_INFO_T *var, NC_GRP_INFO_T *grp, nc_bool_t write_dimid)
1555 NC_HDF5_GRP_INFO_T *hdf5_grp;
1556 NC_HDF5_VAR_INFO_T *hdf5_var;
1557 nc_bool_t replace_existing_var = NC_FALSE;
1560 assert(var && var->format_var_info && grp && grp->format_grp_info);
1562 LOG((4,
"%s: writing var %s", __func__, var->hdr.name));
1565 hdf5_grp = (NC_HDF5_GRP_INFO_T *)grp->format_grp_info;
1566 hdf5_var = (NC_HDF5_VAR_INFO_T *)var->format_var_info;
1570 if (var->created && var->fill_val_changed)
1572 replace_existing_var = NC_TRUE;
1573 var->fill_val_changed = NC_FALSE;
1579 flag_atts_dirty(var->att);
1586 if (var->became_coord_var)
1588 if ((NC_DIM_INFO_T *)ncindexlookup(grp->dim, var->hdr.name))
1592 if ((retval = var_exists(hdf5_grp->hdf_grpid, var->hdr.name, &exists)))
1598 replace_existing_var = NC_TRUE;
1599 flag_atts_dirty(var->att);
1606 if (replace_existing_var)
1611 if ((d1 = (NC_DIM_INFO_T *)ncindexlookup(grp->dim, var->hdr.name)))
1614 assert(d1->format_dim_info && d1->hdr.name);
1616 if ((retval = var_exists(hdf5_grp->hdf_grpid, var->hdr.name, &exists)))
1624 dsid = ((NC_HDF5_VAR_INFO_T *)d1->coord_var->format_var_info)->hdf_datasetid;
1626 dsid = ((NC_HDF5_DIM_INFO_T *)d1->format_dim_info)->hdf_dimscaleid;
1632 if ((retval = rec_detach_scales(grp->nc4_info->root_grp,
1633 var->dimids[0], dsid)))
1641 if (var->was_coord_var && var->dimscale_attached)
1648 if ((retval = remove_coord_atts(hdf5_var->hdf_datasetid)))
1652 for (d = 0; d < var->ndims; d++)
1654 if (var->dimscale_attached[d])
1657 assert(var->dim[d] && var->dim[d]->hdr.id == var->dimids[d] &&
1658 var->dim[d]->format_dim_info);
1661 if (var->dim[d]->coord_var)
1662 dsid = ((NC_HDF5_VAR_INFO_T *)var->dim[d]->coord_var->format_var_info)->hdf_datasetid;
1664 dsid = ((NC_HDF5_DIM_INFO_T *)var->dim[d]->format_dim_info)->hdf_dimscaleid;
1668 if (H5DSdetach_scale(hdf5_var->hdf_datasetid, dsid, d) < 0)
1670 var->dimscale_attached[d] = NC_FALSE;
1676 if (replace_existing_var)
1679 if (hdf5_var->hdf_datasetid && H5Dclose(hdf5_var->hdf_datasetid) < 0)
1681 hdf5_var->hdf_datasetid = 0;
1684 if (H5Gunlink(hdf5_grp->hdf_grpid, var->hdr.name) < 0)
1689 if (var->is_new_var || replace_existing_var)
1691 if ((retval = var_create_dataset(grp, var, write_dimid)))
1696 if (write_dimid && var->ndims)
1697 if ((retval = write_netcdf4_dimid(hdf5_var->hdf_datasetid,
1702 if (replace_existing_var)
1708 if ((retval = rec_reattach_scales(grp->nc4_info->root_grp,
1709 var->dimids[0], hdf5_var->hdf_datasetid)))
1716 if (var->dimscale_attached)
1717 memset(var->dimscale_attached, 0,
sizeof(nc_bool_t) * var->ndims);
1722 var->was_coord_var = NC_FALSE;
1723 var->became_coord_var = NC_FALSE;
1726 if (var->attr_dirty)
1729 if ((retval = write_attlist(var->att, var->hdr.id, grp)))
1731 var->attr_dirty = NC_FALSE;
1751 nc4_create_dim_wo_var(NC_DIM_INFO_T *dim)
1753 NC_HDF5_DIM_INFO_T *hdf5_dim;
1754 NC_HDF5_GRP_INFO_T *hdf5_grp;
1755 hid_t spaceid = -1, create_propid = -1;
1756 hsize_t dims[1], max_dims[1], chunk_dims[1] = {1};
1760 LOG((4,
"%s: creating dim %s", __func__, dim->hdr.name));
1763 assert(!dim->coord_var);
1766 hdf5_grp = (NC_HDF5_GRP_INFO_T *)dim->container->format_grp_info;
1767 hdf5_dim = (NC_HDF5_DIM_INFO_T *)dim->format_dim_info;
1770 if ((create_propid = H5Pcreate(H5P_DATASET_CREATE)) < 0)
1774 if (H5Pset_obj_track_times(create_propid, 0) < 0)
1779 max_dims[0] = dim->len;
1785 max_dims[0] = H5S_UNLIMITED;
1786 if (H5Pset_chunk(create_propid, 1, chunk_dims) < 0)
1791 if ((spaceid = H5Screate_simple(1, dims, max_dims)) < 0)
1795 if (H5Pset_attr_creation_order(create_propid, H5P_CRT_ORDER_TRACKED|
1796 H5P_CRT_ORDER_INDEXED) < 0)
1800 LOG((4,
"%s: about to H5Dcreate1 a dimscale dataset %s", __func__,
1802 if ((hdf5_dim->hdf_dimscaleid = H5Dcreate2(hdf5_grp->hdf_grpid, dim->hdr.name,
1803 H5T_IEEE_F32BE, spaceid,
1804 H5P_DEFAULT, create_propid,
1811 sprintf(dimscale_wo_var,
"%s%10d", DIM_WITHOUT_VARIABLE, (
int)dim->len);
1812 if (H5DSset_scale(hdf5_dim->hdf_dimscaleid, dimscale_wo_var) < 0)
1818 if ((retval = write_netcdf4_dimid(hdf5_dim->hdf_dimscaleid, dim->hdr.id)))
1822 if (spaceid > 0 && H5Sclose(spaceid) < 0)
1824 if (create_propid > 0 && H5Pclose(create_propid) < 0)
1842 write_dim(NC_DIM_INFO_T *dim, NC_GRP_INFO_T *grp, nc_bool_t write_dimid)
1844 NC_HDF5_DIM_INFO_T *hdf5_dim;
1847 assert(dim && dim->format_dim_info && grp && grp->format_grp_info);
1850 hdf5_dim = (NC_HDF5_DIM_INFO_T *)dim->format_dim_info;
1856 if (!hdf5_dim->hdf_dimscaleid)
1857 if ((retval = nc4_create_dim_wo_var(dim)))
1863 NC_VAR_INFO_T *v1 = NULL;
1865 assert(dim->unlimited);
1869 v1 = dim->coord_var;
1872 NC_HDF5_VAR_INFO_T *hdf5_v1;
1876 hdf5_v1 = (NC_HDF5_VAR_INFO_T *)v1->format_var_info;
1880 if (!(new_size = malloc(v1->ndims *
sizeof(hsize_t))))
1882 for (d1 = 0; d1 < v1->ndims; d1++)
1884 assert(v1->dim[d1] && v1->dim[d1]->hdr.id == v1->dimids[d1]);
1885 new_size[d1] = v1->dim[d1]->len;
1887 if (H5Dset_extent(hdf5_v1->hdf_datasetid, new_size) < 0)
1897 if (write_dimid && hdf5_dim->hdf_dimscaleid)
1898 if ((retval = write_netcdf4_dimid(hdf5_dim->hdf_dimscaleid, dim->hdr.id)))
1919 nc4_rec_write_metadata(NC_GRP_INFO_T *grp, nc_bool_t bad_coord_order)
1921 NC_DIM_INFO_T *dim = NULL;
1922 NC_VAR_INFO_T *var = NULL;
1923 NC_GRP_INFO_T *child_grp = NULL;
1924 int coord_varid = -1;
1930 assert(grp && grp->hdr.name &&
1931 ((NC_HDF5_GRP_INFO_T *)(grp->format_grp_info))->hdf_grpid);
1932 LOG((3,
"%s: grp->hdr.name %s, bad_coord_order %d", __func__, grp->hdr.name,
1936 if ((retval = write_attlist(grp->att,
NC_GLOBAL, grp)))
1941 dim = (NC_DIM_INFO_T *)ncindexith(grp->dim, dim_index);
1942 var = (NC_VAR_INFO_T *)ncindexith(grp->vars, var_index);
1949 nc_bool_t found_coord, wrote_coord;
1953 for (found_coord = NC_FALSE; dim && !found_coord; )
1955 if (!dim->coord_var)
1957 if ((retval = write_dim(dim, grp, bad_coord_order)))
1962 coord_varid = dim->coord_var->hdr.id;
1963 found_coord = NC_TRUE;
1965 dim = (NC_DIM_INFO_T *)ncindexith(grp->dim, ++dim_index);
1970 for (wrote_coord = NC_FALSE; var && !wrote_coord; )
1972 if ((retval = write_var(var, grp, bad_coord_order)))
1974 if (found_coord && var->hdr.id == coord_varid)
1975 wrote_coord = NC_TRUE;
1976 var = (NC_VAR_INFO_T *)ncindexith(grp->vars, ++var_index);
1981 if ((retval = attach_dimscales(grp)))
1985 for (i = 0; i < ncindexsize(grp->children); i++)
1987 child_grp = (NC_GRP_INFO_T *)ncindexith(grp->children, i);
1989 if ((retval = nc4_rec_write_metadata(child_grp, bad_coord_order)))
2005 nc4_rec_write_groups_types(NC_GRP_INFO_T *grp)
2007 NC_GRP_INFO_T *child_grp;
2008 NC_HDF5_GRP_INFO_T *hdf5_grp;
2009 NC_TYPE_INFO_T *type;
2013 assert(grp && grp->hdr.name && grp->format_grp_info);
2014 LOG((3,
"%s: grp->hdr.name %s", __func__, grp->hdr.name));
2017 hdf5_grp = (NC_HDF5_GRP_INFO_T *)grp->format_grp_info;
2020 if (!hdf5_grp->hdf_grpid)
2021 if ((retval = create_group(grp)))
2027 if ((retval = write_nc3_strict_att(hdf5_grp->hdf_grpid)))
2031 for(i=0;i<ncindexsize(grp->type);i++) {
2032 type = (NC_TYPE_INFO_T *)ncindexith(grp->type, i);
2034 if ((retval = commit_type(grp, type)))
2039 for(i=0;i<ncindexsize(grp->children);i++) {
2040 if((child_grp = (NC_GRP_INFO_T*)ncindexith(grp->children,i)) == NULL)
continue;
2041 if ((retval = nc4_rec_write_groups_types(child_grp)))
2061 nc4_rec_match_dimscales(NC_GRP_INFO_T *grp)
2069 assert(grp && grp->hdr.name);
2070 LOG((4,
"%s: grp->hdr.name %s", __func__, grp->hdr.name));
2073 for (i = 0; i < ncindexsize(grp->children); i++)
2075 g = (NC_GRP_INFO_T*)ncindexith(grp->children, i);
2077 if ((retval = nc4_rec_match_dimscales(g)))
2083 for (i = 0; i < ncindexsize(grp->vars); i++)
2085 NC_HDF5_VAR_INFO_T *hdf5_var;
2090 var = (NC_VAR_INFO_T*)ncindexith(grp->vars, i);
2091 assert(var && var->format_var_info);
2092 hdf5_var = (NC_HDF5_VAR_INFO_T *)var->format_var_info;
2110 for (d = 0; d < ndims; d++)
2112 if (var->dim[d] == NULL) {
2113 nc4_find_dim(grp, var->dimids[d], &var->dim[d], NULL);
2125 if (hdf5_var->dimscale_hdf5_objids)
2127 for (d = 0; d < var->ndims; d++)
2129 nc_bool_t finished = NC_FALSE;
2130 LOG((5,
"%s: var %s has dimscale info...", __func__, var->hdr.name));
2133 for (g = grp; g && !finished; g = g->parent)
2136 for (j = 0; j < ncindexsize(g->dim); j++)
2139 NC_HDF5_DIM_INFO_T *hdf5_dim;
2140 dim = (NC_DIM_INFO_T *)ncindexith(g->dim, j);
2141 assert(dim && dim->format_dim_info);
2142 hdf5_dim = (NC_HDF5_DIM_INFO_T *)dim->format_dim_info;
2146 if (hdf5_var->dimscale_hdf5_objids[d].fileno[0] == hdf5_dim->hdf5_objid.fileno[0] &&
2147 hdf5_var->dimscale_hdf5_objids[d].objno[0] == hdf5_dim->hdf5_objid.objno[0] &&
2148 hdf5_var->dimscale_hdf5_objids[d].fileno[1] == hdf5_dim->hdf5_objid.fileno[1] &&
2149 hdf5_var->dimscale_hdf5_objids[d].objno[1] == hdf5_dim->hdf5_objid.objno[1])
2151 LOG((4,
"%s: for dimension %d, found dim %s", __func__,
2153 var->dimids[d] = dim->hdr.id;
2160 LOG((5,
"%s: dimid for this dimscale is %d", __func__,
2161 var->type_info->hdr.id));
2168 hsize_t *h5dimlen = NULL, *h5dimlenmax = NULL;
2172 if ((spaceid = H5Dget_space(hdf5_var->hdf_datasetid)) < 0)
2178 if (!(h5dimlen = malloc(var->ndims *
sizeof(hsize_t))))
2180 if (!(h5dimlenmax = malloc(var->ndims *
sizeof(hsize_t))))
2185 if ((dataset_ndims = H5Sget_simple_extent_dims(spaceid, h5dimlen,
2186 h5dimlenmax)) < 0) {
2191 if (dataset_ndims != var->ndims) {
2200 if (H5Sget_simple_extent_type(spaceid) != H5S_SCALAR)
2205 if (H5Sclose(spaceid) < 0) {
2214 for (d = 0; d < var->ndims; d++)
2219 for(match=-1,k=0;k<ncindexsize(grp->dim);k++) {
2220 if((dim = (NC_DIM_INFO_T*)ncindexith(grp->dim,k)) == NULL)
continue;
2221 if ((dim->len == h5dimlen[d]) &&
2222 ((h5dimlenmax[d] == H5S_UNLIMITED && dim->unlimited) ||
2223 (h5dimlenmax[d] != H5S_UNLIMITED && !dim->unlimited)))
2231 sprintf(phony_dim_name,
"phony_dim_%d", grp->nc4_info->next_dimid);
2232 LOG((3,
"%s: creating phony dim for var %s", __func__, var->hdr.name));
2233 if ((retval = nc4_dim_list_add(grp, phony_dim_name, h5dimlen[d], -1, &dim)))
2240 if (!(dim->format_dim_info = calloc(1,
sizeof(NC_HDF5_DIM_INFO_T))))
2242 if (h5dimlenmax[d] == H5S_UNLIMITED)
2243 dim->unlimited = NC_TRUE;
2247 var->dimids[d] = dim->hdr.id;
2274 nc4_get_typeclass(
const NC_FILE_INFO_T *h5,
nc_type xtype,
int *type_class)
2278 LOG((4,
"%s xtype: %d", __func__, xtype));
2318 NC_TYPE_INFO_T *type;
2321 if ((retval = nc4_find_type(h5, xtype, &type)))
2326 *type_class = type->nc_type_class;
2345 reportobject(
int uselog, hid_t
id,
unsigned int type)
2347 char name[NC_HDF5_MAX_NAME];
2349 const char*
typename = NULL;
2350 long long printid = (
long long)
id;
2352 len = H5Iget_name(
id, name, NC_HDF5_MAX_NAME);
2357 case H5F_OBJ_FILE:
typename =
"File";
break;
2358 case H5F_OBJ_DATASET:
typename =
"Dataset";
break;
2359 case H5F_OBJ_GROUP:
typename =
"Group";
break;
2360 case H5F_OBJ_DATATYPE:
typename =
"Datatype";
break;
2362 typename =
"Attribute";
2363 len = H5Aget_name(
id, NC_HDF5_MAX_NAME, name);
2364 if(len < 0) len = 0;
2367 default:
typename =
"<unknown>";
break;
2371 LOG((0,
"Type = %s(%lld) name='%s'",
typename,printid,name));
2375 fprintf(stderr,
"Type = %s(%lld) name='%s'",
typename,printid,name);
2391 reportopenobjectsT(
int uselog, hid_t fid,
int ntypes,
unsigned int* otypes)
2395 size_t maxobjs = -1;
2396 hid_t* idlist = NULL;
2401 LOG((0,
"\nReport: open objects on %lld",(
long long)fid));
2404 fprintf(stdout,
"\nReport: open objects on %lld\n",(
long long)fid);
2405 maxobjs = H5Fget_obj_count(fid,H5F_OBJ_ALL);
2406 if(idlist != NULL) free(idlist);
2407 idlist = (hid_t*)malloc(
sizeof(hid_t)*maxobjs);
2408 for(t=0;t<ntypes;t++) {
2409 unsigned int ot = otypes[t];
2410 ocount = H5Fget_obj_ids(fid,ot,maxobjs,idlist);
2411 for(i=0;i<ocount;i++) {
2412 hid_t o = idlist[i];
2413 reportobject(uselog,o,ot);
2416 if(idlist != NULL) free(idlist);
2428 reportopenobjects(
int uselog, hid_t fid)
2430 unsigned int OTYPES[5] = {H5F_OBJ_FILE, H5F_OBJ_DATASET, H5F_OBJ_GROUP,
2431 H5F_OBJ_DATATYPE, H5F_OBJ_ATTR};
2433 reportopenobjectsT(uselog, fid ,5, OTYPES);
2444 showopenobjects5(NC_FILE_INFO_T* h5)
2446 NC_HDF5_FILE_INFO_T *hdf5_info;
2448 assert(h5 && h5->format_file_info);
2449 hdf5_info = (NC_HDF5_FILE_INFO_T *)h5->format_file_info;
2451 fprintf(stderr,
"===== begin showopenobjects =====\n");
2452 reportopenobjects(0,hdf5_info->hdfid);
2453 fprintf(stderr,
"===== end showopenobjects =====\n");
2466 showopenobjects(
int ncid)
2468 NC_FILE_INFO_T* h5 = NULL;
2471 if (nc4_find_nc_grp_h5(ncid, NULL, NULL, &h5) !=
NC_NOERR)
2472 fprintf(stderr,
"failed\n");
2474 showopenobjects5(h5);
2490 NC4_hdf5get_libversion(
unsigned* major,
unsigned* minor,
unsigned* release)
2492 if(H5get_libversion(major,minor,release) < 0)
2508 NC4_hdf5get_superblock(
struct NC_FILE_INFO* h5,
int* idp)
2510 NC_HDF5_FILE_INFO_T *hdf5_info;
2515 assert(h5 && h5->format_file_info);
2516 hdf5_info = (NC_HDF5_FILE_INFO_T *)h5->format_file_info;
2518 if((plist = H5Fget_create_plist(hdf5_info->hdfid)) < 0)
2520 if(H5Pget_version(plist, &super, NULL, NULL, NULL) < 0)
2522 if(idp) *idp = (int)super;
2524 if(plist >= 0) H5Pclose(plist);
2528 static int NC4_get_strict_att(NC_FILE_INFO_T*);
2529 static int NC4_walk(hid_t,
int*);
2556 NC4_isnetcdf4(
struct NC_FILE_INFO* h5)
2563 isnc4 = NC4_get_strict_att(h5);
2569 stat = NC4_walk(((NC_HDF5_GRP_INFO_T *)(h5->root_grp->format_grp_info))->hdf_grpid,
2574 isnc4 = (count >= 2);
2589 NC4_get_strict_att(NC_FILE_INFO_T *h5)
2595 grpid = ((NC_HDF5_GRP_INFO_T *)(h5->root_grp->format_grp_info))->hdf_grpid;
2598 attid = H5Aopen_name(grpid, NC3_STRICT_ATT_NAME);
2613 NC4_walk(hid_t gid,
int* countp)
2622 char name[NC_HDF5_MAX_NAME];
2625 err = H5Gget_num_objs(gid, &nobj);
2626 if(err < 0)
return err;
2628 for(i = 0; i < nobj; i++) {
2630 len = H5Gget_objname_by_idx(gid,(hsize_t)i,name,(
size_t)NC_HDF5_MAX_NAME);
2631 if(len < 0)
return len;
2633 otype = H5Gget_objtype_by_idx(gid,(
size_t)i);
2636 grpid = H5Gopen(gid,name);
2637 NC4_walk(grpid,countp);
2642 if(strcmp(name,
"phony_dim")==0)
2643 *countp = *countp + 1;
2644 dsid = H5Dopen(gid,name);
2645 na = H5Aget_num_attrs(dsid);
2646 for(j = 0; j < na; j++) {
2647 hid_t aid = H5Aopen_idx(dsid,(
unsigned int) j);
2649 const NC_reservedatt* ra;
2650 ssize_t len = H5Aget_name(aid, NC_HDF5_MAX_NAME, name);
2651 if(len < 0)
return len;
2654 ra = NC_findreserved(name);
2656 *countp = *countp + 1;
2674 filterlookup(
int id)
2678 filters = nclistnew();
2679 for(i=0;i<nclistlength(filters);i++) {
2680 NC_FILTER_INFO* x = nclistget(filters,i);
2681 if(x != NULL && x->id ==
id)
return i;
2687 reclaiminfo(NC_FILTER_INFO* info)
2690 nullfree(info->info);
2695 filterremove(
int pos)
2697 NC_FILTER_INFO* info = NULL;
2699 filters = nclistnew();
2700 if(pos < 0 || pos >= nclistlength(filters))
2702 info = nclistget(filters,pos);
2704 nclistremove(filters,pos);
2708 static NC_FILTER_INFO*
2709 dupfilterinfo(NC_FILTER_INFO* info)
2711 NC_FILTER_INFO* dup = NULL;
2712 if(info == NULL)
goto fail;
2713 if(info->info == NULL)
goto fail;
2714 if((dup = calloc(1,
sizeof(NC_FILTER_INFO))) == NULL)
goto fail;
2716 if((dup->info = calloc(1,
sizeof(H5Z_class2_t))) == NULL)
goto fail;
2718 H5Z_class2_t* h5dup = (H5Z_class2_t*)dup->info;
2719 H5Z_class2_t* h5info = (H5Z_class2_t*)info->info;
2729 nc4_filter_action(
int op,
int format,
int id, NC_FILTER_INFO* info)
2732 H5Z_class2_t* h5filterinfo = NULL;
2735 NC_FILTER_INFO* dup = NULL;
2737 if(format != NC_FILTER_FORMAT_HDF5)
2742 if(info == NULL || info->info == NULL)
2744 if(info->version != NC_FILTER_INFO_VERSION
2745 || info->format != NC_FILTER_FORMAT_HDF5)
2747 h5filterinfo = info->info;
2749 if(info->id != h5filterinfo->id)
2752 if((pos = filterlookup(
id)) >= 0)
2754 if((herr = H5Zregister(h5filterinfo)) < 0)
2757 if((dup = dupfilterinfo(info)) == NULL)
2759 nclistpush(filters,dup);
2765 if((pos = filterlookup(
id)) < 0)
2767 if((herr = H5Zunregister(
id)) < 0)
2769 if((stat=filterremove(pos)))
goto done;
2775 if((pos = filterlookup(
id)) < 0)
2778 *info = *((NC_FILTER_INFO*)nclistget(filters,pos));
#define NC_ENOMEM
Memory allocation (malloc) failure.
#define NC_ENOTNC4
Attempting netcdf-4 operation on netcdf-3 file.
#define NC_CHAR
ISO/ASCII character.
#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
#define NC_EINTERNAL
NetCDF Library Internal Error.
#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 H5Z_FILTER_SZIP
ID of HDF SZIP filter.
#define NC_BYTE
signed 1 byte integer
size_t len
Length of VL data (in base type units)
#define NC_ENAMEINUSE
String match to name in use.
#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_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