18 #include "hdf5internal.h"
21 #ifdef HAVE_INTTYPES_H
22 #define __STDC_FORMAT_MACROS
26 #define NC_HDF5_MAX_NAME 1024
37 flag_atts_dirty(NCindex *attlist) {
39 NC_ATT_INFO_T *att = NULL;
46 for(i=0;i<ncindexsize(attlist);i++) {
47 att = (NC_ATT_INFO_T*)ncindexith(attlist,i);
48 if(att == NULL)
continue;
72 rec_reattach_scales(NC_GRP_INFO_T *grp,
int dimid, hid_t dimscaleid)
75 NC_GRP_INFO_T *child_grp;
79 assert(grp && grp->hdr.name && dimid >= 0 && dimscaleid >= 0);
80 LOG((3,
"%s: grp->hdr.name %s", __func__, grp->hdr.name));
83 for (i = 0; i < ncindexsize(grp->children); i++)
85 child_grp = (NC_GRP_INFO_T*)ncindexith(grp->children, i);
87 if ((retval = rec_reattach_scales(child_grp, dimid, dimscaleid)))
92 for (i = 0; i < ncindexsize(grp->vars); i++)
94 NC_HDF5_VAR_INFO_T *hdf5_var;
96 var = (NC_VAR_INFO_T*)ncindexith(grp->vars,i);
97 assert(var && var->format_var_info);
98 hdf5_var = (NC_HDF5_VAR_INFO_T *)var->format_var_info;
100 for (d = 0; d < var->ndims; d++)
102 if (var->dimids[d] == dimid && !var->dimscale)
104 LOG((2,
"%s: attaching scale for dimid %d to var %s",
105 __func__, var->dimids[d], var->hdr.name));
108 if (H5DSattach_scale(hdf5_var->hdf_datasetid,
111 var->dimscale_attached[d] = NC_TRUE;
136 rec_detach_scales(NC_GRP_INFO_T *grp,
int dimid, hid_t dimscaleid)
139 NC_GRP_INFO_T *child_grp;
143 assert(grp && grp->hdr.name && dimid >= 0 && dimscaleid >= 0);
144 LOG((3,
"%s: grp->hdr.name %s", __func__, grp->hdr.name));
147 for(i=0;i<ncindexsize(grp->children);i++) {
148 child_grp = (NC_GRP_INFO_T*)ncindexith(grp->children,i);
149 if(child_grp == NULL)
continue;
150 if ((retval = rec_detach_scales(child_grp, dimid, dimscaleid)))
155 for (i = 0; i < ncindexsize(grp->vars); i++)
157 NC_HDF5_VAR_INFO_T *hdf5_var;
158 var = (NC_VAR_INFO_T*)ncindexith(grp->vars, i);
159 assert(var && var->format_var_info);
160 hdf5_var = (NC_HDF5_VAR_INFO_T *)var->format_var_info;
162 for (d = 0; d < var->ndims; d++)
164 if (var->dimids[d] == dimid && !var->dimscale)
166 LOG((2,
"%s: detaching scale for dimid %d to var %s",
167 __func__, var->dimids[d], var->hdr.name));
170 if (var->dimscale_attached && var->dimscale_attached[d])
172 if (H5DSdetach_scale(hdf5_var->hdf_datasetid,
175 var->dimscale_attached[d] = NC_FALSE;
196 nc4_open_var_grp2(NC_GRP_INFO_T *grp,
int varid, hid_t *dataset)
199 NC_HDF5_VAR_INFO_T *hdf5_var;
201 assert(grp && grp->format_grp_info && dataset);
204 if (!(var = (NC_VAR_INFO_T *)ncindexith(grp->vars, varid)))
206 assert(var && var->hdr.id == varid && var->format_var_info);
207 hdf5_var = (NC_HDF5_VAR_INFO_T *)var->format_var_info;
210 if (!hdf5_var->hdf_datasetid)
212 NC_HDF5_GRP_INFO_T *hdf5_grp;
213 hdf5_grp = (NC_HDF5_GRP_INFO_T *)grp->format_grp_info;
215 if ((hdf5_var->hdf_datasetid = H5Dopen2(hdf5_grp->hdf_grpid,
216 var->hdr.name, H5P_DEFAULT)) < 0)
220 *dataset = hdf5_var->hdf_datasetid;
237 nc4_get_fill_value(NC_FILE_INFO_T *h5, NC_VAR_INFO_T *var,
void **fillp)
243 if (var->type_info->nc_type_class ==
NC_VLEN)
245 else if (var->type_info->nc_type_class ==
NC_STRING)
246 size =
sizeof(
char *);
249 if ((retval = nc4_get_typelen_mem(h5, var->type_info->hdr.id, &size)))
255 if (!((*fillp) = calloc(1, size)))
262 LOG((4,
"Found a fill value for var %s", var->hdr.name));
263 if (var->type_info->nc_type_class ==
NC_VLEN)
266 size_t basetypesize = 0;
268 if((retval=nc4_get_typelen_mem(h5, var->type_info->u.v.base_nc_typeid, &basetypesize)))
271 fv_vlen->
len = in_vlen->
len;
272 if (!(fv_vlen->p = malloc(basetypesize * in_vlen->
len)))
278 memcpy(fv_vlen->p, in_vlen->
p, in_vlen->
len * basetypesize);
280 else if (var->type_info->nc_type_class ==
NC_STRING)
282 if (*(
char **)var->fill_value)
283 if (!(**(
char ***)fillp = strdup(*(
char **)var->fill_value)))
291 memcpy((*fillp), var->fill_value, size);
295 if (nc4_get_default_fill_value(var->type_info, *fillp))
324 nc4_get_hdf_typeid(NC_FILE_INFO_T *h5,
nc_type xtype,
325 hid_t *hdf_typeid,
int endianness)
327 NC_TYPE_INFO_T *type;
331 assert(hdf_typeid && h5);
343 if ((
typeid = H5Tcopy(H5T_C_S1)) < 0)
345 if (H5Tset_strpad(
typeid, H5T_STR_NULLTERM) < 0)
347 if(H5Tset_cset(
typeid, H5T_CSET_ASCII) < 0)
351 *hdf_typeid =
typeid;
356 if ((
typeid = H5Tcopy(H5T_C_S1)) < 0)
358 if (H5Tset_size(
typeid, H5T_VARIABLE) < 0)
360 if(H5Tset_cset(
typeid, H5T_CSET_UTF8) < 0)
364 *hdf_typeid =
typeid;
375 typeid = H5T_STD_I8LE;
377 typeid = H5T_STD_I8BE;
379 typeid = H5T_NATIVE_SCHAR;
384 typeid = H5T_STD_I16LE;
386 typeid = H5T_STD_I16BE;
388 typeid = H5T_NATIVE_SHORT;
393 typeid = H5T_STD_I32LE;
395 typeid = H5T_STD_I32BE;
397 typeid = H5T_NATIVE_INT;
402 typeid = H5T_STD_U8LE;
404 typeid = H5T_STD_U8BE;
406 typeid = H5T_NATIVE_UCHAR;
411 typeid = H5T_STD_U16LE;
413 typeid = H5T_STD_U16BE;
415 typeid = H5T_NATIVE_USHORT;
420 typeid = H5T_STD_U32LE;
422 typeid = H5T_STD_U32BE;
424 typeid = H5T_NATIVE_UINT;
429 typeid = H5T_STD_I64LE;
431 typeid = H5T_STD_I64BE;
433 typeid = H5T_NATIVE_LLONG;
438 typeid = H5T_STD_U64LE;
440 typeid = H5T_STD_U64BE;
442 typeid = H5T_NATIVE_ULLONG;
447 typeid = H5T_IEEE_F32LE;
449 typeid = H5T_IEEE_F32BE;
451 typeid = H5T_NATIVE_FLOAT;
456 typeid = H5T_IEEE_F64LE;
458 typeid = H5T_IEEE_F64BE;
460 typeid = H5T_NATIVE_DOUBLE;
465 if (nc4_find_type(h5, xtype, &type))
469 typeid = ((NC_HDF5_TYPE_INFO_T *)type->format_type_info)->hdf_typeid;
475 if ((*hdf_typeid = H5Tcopy(
typeid)) < 0)
479 assert(*hdf_typeid != -1);
482 if (
typeid > 0 && H5Tclose(
typeid) < 0)
502 put_att_grpa(NC_GRP_INFO_T *grp,
int varid, NC_ATT_INFO_T *att)
504 NC_HDF5_GRP_INFO_T *hdf5_grp;
505 hid_t datasetid = 0, locid;
506 hid_t attid = 0, spaceid = 0, file_typeid = 0;
507 hid_t existing_att_typeid = 0, existing_attid = 0, existing_spaceid = 0;
512 int phoney_data = 99;
515 assert(att->hdr.name && grp && grp->format_grp_info);
516 LOG((3,
"%s: varid %d att->hdr.id %d att->hdr.name %s att->nc_typeid %d "
517 "att->len %d", __func__, varid, att->hdr.id, att->hdr.name,
518 att->nc_typeid, att->len));
521 hdf5_grp = (NC_HDF5_GRP_INFO_T *)grp->format_grp_info;
524 if (grp->nc4_info->no_write)
529 locid = hdf5_grp->hdf_grpid;
532 if ((retval = nc4_open_var_grp2(grp, varid, &datasetid)))
540 if ((retval = nc4_get_hdf_typeid(grp->nc4_info, att->nc_typeid,
551 else if (att->stdata)
563 size_t string_size = dims[0];
567 if ((spaceid = H5Screate(H5S_NULL)) < 0)
572 if ((spaceid = H5Screate(H5S_SCALAR)) < 0)
575 if (H5Tset_size(file_typeid, string_size) < 0)
577 if (H5Tset_strpad(file_typeid, H5T_STR_NULLTERM) < 0)
584 if ((spaceid = H5Screate(H5S_NULL)) < 0)
589 if ((spaceid = H5Screate_simple(1, dims, NULL)) < 0)
595 if ((attr_exists = H5Aexists(locid, att->hdr.name)) < 0)
602 if ((existing_attid = H5Aopen(locid, att->hdr.name, H5P_DEFAULT)) < 0)
606 if ((existing_att_typeid = H5Aget_type(existing_attid)) < 0)
610 if ((existing_spaceid = H5Aget_space(existing_attid)) < 0)
612 if ((npoints = H5Sget_simple_extent_npoints(existing_spaceid)) < 0)
616 if (file_typeid != existing_att_typeid || npoints != att->len)
618 if (H5Adelete(locid, att->hdr.name) < 0)
628 if ((attid = H5Acreate(locid, att->hdr.name, file_typeid, spaceid,
633 if (H5Awrite(attid, file_typeid, data) < 0)
637 if (file_typeid && H5Tclose(file_typeid))
639 if (attid > 0 && H5Aclose(attid) < 0)
641 if (existing_att_typeid && H5Tclose(existing_att_typeid))
643 if (existing_attid > 0 && H5Aclose(existing_attid) < 0)
645 if (spaceid > 0 && H5Sclose(spaceid) < 0)
647 if (existing_spaceid > 0 && H5Sclose(existing_spaceid) < 0)
664 write_attlist(NCindex *attlist,
int varid, NC_GRP_INFO_T *grp)
670 for(i = 0; i < ncindexsize(attlist); i++)
672 att = (NC_ATT_INFO_T *)ncindexith(attlist, i);
676 LOG((4,
"%s: writing att %s to varid %d", __func__, att->hdr.name, varid));
677 if ((retval = put_att_grpa(grp, varid, att)))
679 att->dirty = NC_FALSE;
680 att->created = NC_TRUE;
700 write_coord_dimids(NC_VAR_INFO_T *var)
702 NC_HDF5_VAR_INFO_T *hdf5_var;
703 hsize_t coords_len[1];
704 hid_t c_spaceid = -1, c_attid = -1;
707 assert(var && var->format_var_info);
710 hdf5_var = (NC_HDF5_VAR_INFO_T *)var->format_var_info;
713 coords_len[0] = var->ndims;
714 if ((c_spaceid = H5Screate_simple(1, coords_len, coords_len)) < 0)
718 if ((c_attid = H5Acreate(hdf5_var->hdf_datasetid, COORDINATES,
719 H5T_NATIVE_INT, c_spaceid, H5P_DEFAULT)) < 0)
723 if (H5Awrite(c_attid, H5T_NATIVE_INT, var->dimids) < 0)
727 if (c_spaceid >= 0 && H5Sclose(c_spaceid) < 0)
729 if (c_attid >= 0 && H5Aclose(c_attid) < 0)
745 write_netcdf4_dimid(hid_t datasetid,
int dimid)
747 hid_t dimid_spaceid = -1, dimid_attid = -1;
752 if ((dimid_spaceid = H5Screate(H5S_SCALAR)) < 0)
756 if ((attr_exists = H5Aexists(datasetid, NC_DIMID_ATT_NAME)) < 0)
759 dimid_attid = H5Aopen_by_name(datasetid,
".", NC_DIMID_ATT_NAME,
760 H5P_DEFAULT, H5P_DEFAULT);
763 dimid_attid = H5Acreate(datasetid, NC_DIMID_ATT_NAME,
764 H5T_NATIVE_INT, dimid_spaceid, H5P_DEFAULT);
770 LOG((4,
"%s: writing secret dimid %d", __func__, dimid));
771 if (H5Awrite(dimid_attid, H5T_NATIVE_INT, &dimid) < 0)
776 if (dimid_spaceid >= 0 && H5Sclose(dimid_spaceid) < 0)
778 if (dimid_attid >= 0 && H5Aclose(dimid_attid) < 0)
799 var_create_dataset(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var, nc_bool_t write_dimid)
801 NC_HDF5_GRP_INFO_T *hdf5_grp;
802 NC_HDF5_VAR_INFO_T *hdf5_var;
803 hid_t plistid = 0, access_plistid = 0,
typeid = 0, spaceid = 0;
804 hsize_t chunksize[H5S_MAX_RANK], dimsize[H5S_MAX_RANK], maxdimsize[H5S_MAX_RANK];
807 NC_DIM_INFO_T *dim = NULL;
811 assert(grp && grp->format_grp_info && var && var->format_var_info);
813 LOG((3,
"%s:: name %s", __func__, var->hdr.name));
816 hdf5_grp = (NC_HDF5_GRP_INFO_T *)grp->format_grp_info;
817 hdf5_var = (NC_HDF5_VAR_INFO_T *)var->format_var_info;
820 if ((plistid = H5Pcreate(H5P_DATASET_CREATE)) < 0)
822 if ((access_plistid = H5Pcreate(H5P_DATASET_ACCESS)) < 0)
826 if (H5Pset_obj_track_times(plistid, 0) < 0)
830 if ((retval = nc4_get_hdf_typeid(grp->nc4_info, var->type_info->hdr.id, &
typeid,
831 var->type_info->endianness)))
838 if (H5Pset_fill_time(plistid, H5D_FILL_TIME_NEVER) < 0)
843 if ((retval = nc4_get_fill_value(grp->nc4_info, var, &fillp)))
849 if (var->type_info->nc_type_class ==
NC_STRING)
851 if (H5Pset_fill_value(plistid,
typeid, fillp) < 0)
860 hid_t fill_typeid = 0;
862 if ((retval = nc4_get_hdf_typeid(grp->nc4_info, var->type_info->hdr.id, &fill_typeid,
865 if (H5Pset_fill_value(plistid, fill_typeid, fillp) < 0)
867 if (H5Tclose(fill_typeid) < 0)
871 if (H5Tclose(fill_typeid) < 0)
879 if (H5Pset_shuffle(plistid) < 0)
885 if (H5Pset_deflate(plistid, var->deflate_level) < 0)
887 }
else if(var->filterid) {
892 if(var->nparams != 2)
894 options_mask = (int)var->params[0];
895 bits_per_pixel = (
int)var->params[1];
896 if(H5Pset_szip(plistid, options_mask, bits_per_pixel) < 0)
899 herr_t code = H5Pset_filter(plistid, var->filterid, H5Z_FLAG_MANDATORY, var->nparams, var->params);
908 if (H5Pset_fletcher32(plistid) < 0)
920 for (d = 0; d < var->ndims; d++) {
922 assert(dim && dim->hdr.id == var->dimids[d]);
930 if (!var->shuffle && !var->deflate && !var->fletcher32 &&
931 (var->chunksizes == NULL || !var->chunksizes[0]) && !unlimdim)
932 var->contiguous = NC_TRUE;
935 for (d = 0; d < var->ndims; d++)
938 assert(dim && dim->hdr.id == var->dimids[d]);
939 dimsize[d] = dim->unlimited ? NC_HDF5_UNLIMITED_DIMSIZE : dim->len;
940 maxdimsize[d] = dim->unlimited ? H5S_UNLIMITED : (hsize_t)dim->len;
941 if (!var->contiguous) {
942 if (var->chunksizes[d])
943 chunksize[d] = var->chunksizes[d];
947 if (var->type_info->nc_type_class ==
NC_STRING)
948 type_size =
sizeof(
char *);
950 type_size = var->type_info->size;
956 chunksize[d] = pow((
double)DEFAULT_CHUNK_SIZE/type_size,
957 1/(
double)(var->ndims - unlimdim));
961 if (!dim->unlimited && chunksize[d] > dim->len)
962 chunksize[d] = dim->len;
965 var->chunksizes[d] = chunksize[d];
972 if (H5Pset_layout(plistid, H5D_CONTIGUOUS) < 0)
977 if (H5Pset_chunk(plistid, var->ndims, chunksize) < 0)
982 if ((spaceid = H5Screate_simple(var->ndims, dimsize, maxdimsize)) < 0)
987 if ((spaceid = H5Screate(H5S_SCALAR)) < 0)
992 if (H5Pset_attr_creation_order(plistid, H5P_CRT_ORDER_TRACKED|
993 H5P_CRT_ORDER_INDEXED) < 0)
997 if (!var->contiguous && var->chunk_cache_size)
998 if (H5Pset_chunk_cache(access_plistid, var->chunk_cache_nelems,
999 var->chunk_cache_size, var->chunk_cache_preemption) < 0)
1003 name_to_use = var->hdf5_name ? var->hdf5_name : var->hdr.name;
1004 LOG((4,
"%s: about to H5Dcreate2 dataset %s of type 0x%x", __func__,
1005 name_to_use,
typeid));
1006 if ((hdf5_var->hdf_datasetid = H5Dcreate2(hdf5_grp->hdf_grpid, name_to_use,
typeid,
1007 spaceid, H5P_DEFAULT, plistid, access_plistid)) < 0)
1009 var->created = NC_TRUE;
1010 var->is_new_var = NC_FALSE;
1016 if ((retval = write_coord_dimids(var)))
1024 if (H5DSset_scale(hdf5_var->hdf_datasetid, var->hdr.name) < 0)
1035 if ((retval = write_netcdf4_dimid(hdf5_var->hdf_datasetid, var->dimids[0])))
1040 if ((retval = write_attlist(var->att, var->hdr.id, grp)))
1042 var->attr_dirty = NC_FALSE;
1045 if (
typeid > 0 && H5Tclose(
typeid) < 0)
1047 if (plistid > 0 && H5Pclose(plistid) < 0)
1049 if (access_plistid > 0 && H5Pclose(access_plistid) < 0)
1051 if (spaceid > 0 && H5Sclose(spaceid) < 0)
1055 if (var->type_info->nc_type_class ==
NC_VLEN)
1057 else if (var->type_info->nc_type_class ==
NC_STRING && *(
char **)fillp)
1058 free(*(
char **)fillp);
1076 nc4_adjust_var_cache(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var)
1078 size_t chunk_size_bytes = 1;
1083 if (var->contiguous)
1085 #ifdef USE_PARALLEL4
1090 for (d = 0; d < var->ndims; d++)
1091 chunk_size_bytes *= var->chunksizes[d];
1092 if (var->type_info->size)
1093 chunk_size_bytes *= var->type_info->size;
1095 chunk_size_bytes *=
sizeof(
char *);
1100 if (var->chunk_cache_size == CHUNK_CACHE_SIZE)
1101 if (chunk_size_bytes > var->chunk_cache_size)
1103 var->chunk_cache_size = chunk_size_bytes * DEFAULT_CHUNKS_IN_CACHE;
1104 if (var->chunk_cache_size > MAX_DEFAULT_CACHE_SIZE)
1105 var->chunk_cache_size = MAX_DEFAULT_CACHE_SIZE;
1106 if ((retval = nc4_reopen_dataset(grp, var)))
1129 commit_type(NC_GRP_INFO_T *grp, NC_TYPE_INFO_T *type)
1131 NC_HDF5_GRP_INFO_T *hdf5_grp;
1132 NC_HDF5_TYPE_INFO_T *hdf5_type;
1133 hid_t base_hdf_typeid;
1136 assert(grp && grp->format_grp_info && type && type->format_type_info);
1139 hdf5_grp = (NC_HDF5_GRP_INFO_T *)grp->format_grp_info;
1140 hdf5_type = (NC_HDF5_TYPE_INFO_T *)type->format_type_info;
1143 if (type->committed)
1149 NC_FIELD_INFO_T *field;
1150 hid_t hdf_base_typeid, hdf_typeid;
1153 if ((hdf5_type->hdf_typeid = H5Tcreate(H5T_COMPOUND, type->size)) < 0)
1155 LOG((4,
"creating compound type %s hdf_typeid 0x%x", type->hdr.name,
1156 hdf5_type->hdf_typeid));
1158 for(i=0;i<nclistlength(type->u.c.field);i++)
1160 field = (NC_FIELD_INFO_T *)nclistget(type->u.c.field, i);
1162 if ((retval = nc4_get_hdf_typeid(grp->nc4_info, field->nc_typeid,
1163 &hdf_base_typeid, type->endianness)))
1172 for (d = 0; d < field->ndims; d++)
1173 dims[d] = field->dim_size[d];
1174 if ((hdf_typeid = H5Tarray_create(hdf_base_typeid, field->ndims,
1177 if (H5Tclose(hdf_base_typeid) < 0)
1181 if (H5Tclose(hdf_base_typeid) < 0)
1185 hdf_typeid = hdf_base_typeid;
1186 LOG((4,
"inserting field %s offset %d hdf_typeid 0x%x", field->hdr.name,
1187 field->offset, hdf_typeid));
1188 if (H5Tinsert(hdf5_type->hdf_typeid, field->hdr.name, field->offset,
1191 if (H5Tclose(hdf_typeid) < 0)
1195 else if (type->nc_type_class ==
NC_VLEN)
1198 if ((retval = nc4_get_hdf_typeid(grp->nc4_info, type->u.v.base_nc_typeid,
1199 &base_hdf_typeid, type->endianness)))
1203 if ((hdf5_type->hdf_typeid = H5Tvlen_create(base_hdf_typeid)) < 0)
1206 else if (type->nc_type_class ==
NC_OPAQUE)
1209 if ((hdf5_type->hdf_typeid = H5Tcreate(H5T_OPAQUE, type->size)) < 0)
1212 else if (type->nc_type_class ==
NC_ENUM)
1214 NC_ENUM_MEMBER_INFO_T *enum_m;
1217 if (nclistlength(type->u.e.enum_member) == 0)
1221 if ((retval = nc4_get_hdf_typeid(grp->nc4_info, type->u.e.base_nc_typeid,
1222 &base_hdf_typeid, type->endianness)))
1226 if ((hdf5_type->hdf_typeid = H5Tenum_create(base_hdf_typeid)) < 0)
1230 for(i=0;i<nclistlength(type->u.e.enum_member);i++) {
1231 enum_m = (NC_ENUM_MEMBER_INFO_T*)nclistget(type->u.e.enum_member,i);
1232 if (H5Tenum_insert(hdf5_type->hdf_typeid, enum_m->name, enum_m->value) < 0)
1238 LOG((0,
"Unknown class: %d", type->nc_type_class));
1243 if (H5Tcommit(hdf5_grp->hdf_grpid, type->hdr.name, hdf5_type->hdf_typeid) < 0)
1245 type->committed = NC_TRUE;
1246 LOG((4,
"just committed type %s, HDF typeid: 0x%x", type->hdr.name,
1247 hdf5_type->hdf_typeid));
1252 if ((hdf5_type->native_hdf_typeid = H5Tget_native_type(hdf5_type->hdf_typeid,
1253 H5T_DIR_DEFAULT)) < 0)
1270 write_nc3_strict_att(hid_t hdf_grpid)
1272 hid_t attid = 0, spaceid = 0;
1279 if ((attr_exists = H5Aexists(hdf_grpid, NC3_STRICT_ATT_NAME)) < 0)
1286 if ((spaceid = H5Screate(H5S_SCALAR)) < 0)
1288 if ((attid = H5Acreate(hdf_grpid, NC3_STRICT_ATT_NAME,
1289 H5T_NATIVE_INT, spaceid, H5P_DEFAULT)) < 0)
1291 if (H5Awrite(attid, H5T_NATIVE_INT, &one) < 0)
1295 if (spaceid > 0 && (H5Sclose(spaceid) < 0))
1297 if (attid > 0 && (H5Aclose(attid) < 0))
1315 create_group(NC_GRP_INFO_T *grp)
1317 NC_HDF5_GRP_INFO_T *hdf5_grp, *parent_hdf5_grp;
1321 assert(grp && grp->format_grp_info && grp->parent &&
1322 grp->parent->format_grp_info);
1325 hdf5_grp = (NC_HDF5_GRP_INFO_T *)grp->format_grp_info;
1326 parent_hdf5_grp = (NC_HDF5_GRP_INFO_T *)grp->parent->format_grp_info;
1327 assert(parent_hdf5_grp->hdf_grpid);
1331 if ((gcpl_id = H5Pcreate(H5P_GROUP_CREATE)) < 0)
1335 if (H5Pset_obj_track_times(gcpl_id, 0) < 0)
1339 if (H5Pset_link_creation_order(gcpl_id, H5P_CRT_ORDER_TRACKED|H5P_CRT_ORDER_INDEXED) < 0)
1343 if (H5Pset_attr_creation_order(gcpl_id, H5P_CRT_ORDER_TRACKED|H5P_CRT_ORDER_INDEXED) < 0)
1347 if ((hdf5_grp->hdf_grpid = H5Gcreate2(parent_hdf5_grp->hdf_grpid, grp->hdr.name,
1348 H5P_DEFAULT, gcpl_id, H5P_DEFAULT)) < 0)
1352 if (gcpl_id > -1 && H5Pclose(gcpl_id) < 0)
1355 if (hdf5_grp->hdf_grpid > 0 && H5Gclose(hdf5_grp->hdf_grpid) < 0)
1372 attach_dimscales(NC_GRP_INFO_T *grp)
1375 NC_HDF5_VAR_INFO_T *hdf5_var;
1379 for (v = 0; v < ncindexsize(grp->vars); v++)
1382 var = (NC_VAR_INFO_T *)ncindexith(grp->vars, v);
1383 assert(var && var->format_var_info);
1384 hdf5_var = (NC_HDF5_VAR_INFO_T *)var->format_var_info;
1392 for (d = 0; d < var->ndims; d++)
1395 if (var->dimscale_attached)
1397 if (!var->dimscale_attached[d])
1400 assert(var->dim[d] && var->dim[d]->hdr.id == var->dimids[d] &&
1401 var->dim[d]->format_dim_info);
1403 LOG((2,
"%s: attaching scale for dimid %d to var %s",
1404 __func__, var->dimids[d], var->hdr.name));
1407 if (var->dim[d]->coord_var)
1408 dsid = ((NC_HDF5_VAR_INFO_T *)(var->dim[d]->coord_var->format_var_info))->hdf_datasetid;
1410 dsid = ((NC_HDF5_DIM_INFO_T *)var->dim[d]->format_dim_info)->hdf_dimscaleid;
1414 if (H5DSattach_scale(hdf5_var->hdf_datasetid, dsid, d) < 0)
1416 var->dimscale_attached[d] = NC_TRUE;
1436 var_exists(hid_t grpid,
char *name, nc_bool_t *exists)
1444 if ((link_exists = H5Lexists(grpid, name, H5P_DEFAULT)) < 0)
1451 if (H5Gget_objinfo(grpid, name, 1, &statbuf) < 0)
1454 if (H5G_DATASET == statbuf.type)
1477 remove_coord_atts(hid_t hdf_datasetid)
1483 if ((attr_exists = H5Aexists(hdf_datasetid, NC_DIMID_ATT_NAME)) < 0)
1487 if (H5Adelete(hdf_datasetid, NC_DIMID_ATT_NAME) < 0)
1492 if ((attr_exists = H5Aexists(hdf_datasetid,
1493 HDF5_DIMSCALE_CLASS_ATT_NAME)) < 0)
1497 if (H5Adelete(hdf_datasetid, HDF5_DIMSCALE_CLASS_ATT_NAME) < 0)
1500 if ((attr_exists = H5Aexists(hdf_datasetid,
1501 HDF5_DIMSCALE_NAME_ATT_NAME)) < 0)
1505 if (H5Adelete(hdf_datasetid, HDF5_DIMSCALE_NAME_ATT_NAME) < 0)
1526 write_var(NC_VAR_INFO_T *var, NC_GRP_INFO_T *grp, nc_bool_t write_dimid)
1528 NC_HDF5_GRP_INFO_T *hdf5_grp;
1529 NC_HDF5_VAR_INFO_T *hdf5_var;
1530 nc_bool_t replace_existing_var = NC_FALSE;
1533 assert(var && var->format_var_info && grp && grp->format_grp_info);
1535 LOG((4,
"%s: writing var %s", __func__, var->hdr.name));
1538 hdf5_grp = (NC_HDF5_GRP_INFO_T *)grp->format_grp_info;
1539 hdf5_var = (NC_HDF5_VAR_INFO_T *)var->format_var_info;
1543 if (var->created && var->fill_val_changed)
1545 replace_existing_var = NC_TRUE;
1546 var->fill_val_changed = NC_FALSE;
1552 flag_atts_dirty(var->att);
1559 if (var->became_coord_var)
1561 if ((NC_DIM_INFO_T *)ncindexlookup(grp->dim, var->hdr.name))
1565 if ((retval = var_exists(hdf5_grp->hdf_grpid, var->hdr.name, &exists)))
1571 replace_existing_var = NC_TRUE;
1572 flag_atts_dirty(var->att);
1579 if (replace_existing_var)
1584 if ((d1 = (NC_DIM_INFO_T *)ncindexlookup(grp->dim, var->hdr.name)))
1587 assert(d1->format_dim_info && d1->hdr.name);
1589 if ((retval = var_exists(hdf5_grp->hdf_grpid, var->hdr.name, &exists)))
1597 dsid = ((NC_HDF5_VAR_INFO_T *)d1->coord_var->format_var_info)->hdf_datasetid;
1599 dsid = ((NC_HDF5_DIM_INFO_T *)d1->format_dim_info)->hdf_dimscaleid;
1605 if ((retval = rec_detach_scales(grp->nc4_info->root_grp,
1606 var->dimids[0], dsid)))
1614 if (var->was_coord_var && var->dimscale_attached)
1621 if ((retval = remove_coord_atts(hdf5_var->hdf_datasetid)))
1625 for (d = 0; d < var->ndims; d++)
1627 if (var->dimscale_attached[d])
1630 assert(var->dim[d] && var->dim[d]->hdr.id == var->dimids[d] &&
1631 var->dim[d]->format_dim_info);
1634 if (var->dim[d]->coord_var)
1635 dsid = ((NC_HDF5_VAR_INFO_T *)var->dim[d]->coord_var->format_var_info)->hdf_datasetid;
1637 dsid = ((NC_HDF5_DIM_INFO_T *)var->dim[d]->format_dim_info)->hdf_dimscaleid;
1641 if (H5DSdetach_scale(hdf5_var->hdf_datasetid, dsid, d) < 0)
1643 var->dimscale_attached[d] = NC_FALSE;
1649 if (replace_existing_var)
1652 if (hdf5_var->hdf_datasetid && H5Dclose(hdf5_var->hdf_datasetid) < 0)
1654 hdf5_var->hdf_datasetid = 0;
1657 if (H5Gunlink(hdf5_grp->hdf_grpid, var->hdr.name) < 0)
1662 if (var->is_new_var || replace_existing_var)
1664 if ((retval = var_create_dataset(grp, var, write_dimid)))
1669 if (write_dimid && var->ndims)
1670 if ((retval = write_netcdf4_dimid(hdf5_var->hdf_datasetid,
1675 if (replace_existing_var)
1681 if ((retval = rec_reattach_scales(grp->nc4_info->root_grp,
1682 var->dimids[0], hdf5_var->hdf_datasetid)))
1689 if (var->dimscale_attached)
1690 memset(var->dimscale_attached, 0,
sizeof(nc_bool_t) * var->ndims);
1695 var->was_coord_var = NC_FALSE;
1696 var->became_coord_var = NC_FALSE;
1699 if (var->attr_dirty)
1702 if ((retval = write_attlist(var->att, var->hdr.id, grp)))
1704 var->attr_dirty = NC_FALSE;
1724 nc4_create_dim_wo_var(NC_DIM_INFO_T *dim)
1726 NC_HDF5_DIM_INFO_T *hdf5_dim;
1727 NC_HDF5_GRP_INFO_T *hdf5_grp;
1728 hid_t spaceid = -1, create_propid = -1;
1729 hsize_t dims[1], max_dims[1], chunk_dims[1] = {1};
1733 LOG((4,
"%s: creating dim %s", __func__, dim->hdr.name));
1736 assert(!dim->coord_var);
1739 hdf5_grp = (NC_HDF5_GRP_INFO_T *)dim->container->format_grp_info;
1740 hdf5_dim = (NC_HDF5_DIM_INFO_T *)dim->format_dim_info;
1743 if ((create_propid = H5Pcreate(H5P_DATASET_CREATE)) < 0)
1747 if (H5Pset_obj_track_times(create_propid, 0) < 0)
1752 max_dims[0] = dim->len;
1758 max_dims[0] = H5S_UNLIMITED;
1759 if (H5Pset_chunk(create_propid, 1, chunk_dims) < 0)
1764 if ((spaceid = H5Screate_simple(1, dims, max_dims)) < 0)
1768 if (H5Pset_attr_creation_order(create_propid, H5P_CRT_ORDER_TRACKED|
1769 H5P_CRT_ORDER_INDEXED) < 0)
1773 LOG((4,
"%s: about to H5Dcreate1 a dimscale dataset %s", __func__,
1775 if ((hdf5_dim->hdf_dimscaleid = H5Dcreate2(hdf5_grp->hdf_grpid, dim->hdr.name,
1776 H5T_IEEE_F32BE, spaceid,
1777 H5P_DEFAULT, create_propid,
1784 sprintf(dimscale_wo_var,
"%s%10d", DIM_WITHOUT_VARIABLE, (
int)dim->len);
1785 if (H5DSset_scale(hdf5_dim->hdf_dimscaleid, dimscale_wo_var) < 0)
1791 if ((retval = write_netcdf4_dimid(hdf5_dim->hdf_dimscaleid, dim->hdr.id)))
1795 if (spaceid > 0 && H5Sclose(spaceid) < 0)
1797 if (create_propid > 0 && H5Pclose(create_propid) < 0)
1815 write_dim(NC_DIM_INFO_T *dim, NC_GRP_INFO_T *grp, nc_bool_t write_dimid)
1817 NC_HDF5_DIM_INFO_T *hdf5_dim;
1820 assert(dim && dim->format_dim_info && grp && grp->format_grp_info);
1823 hdf5_dim = (NC_HDF5_DIM_INFO_T *)dim->format_dim_info;
1829 if (!hdf5_dim->hdf_dimscaleid)
1830 if ((retval = nc4_create_dim_wo_var(dim)))
1836 NC_VAR_INFO_T *v1 = NULL;
1838 assert(dim->unlimited);
1842 v1 = (NC_VAR_INFO_T *)ncindexlookup(grp->vars, dim->hdr.name);
1845 NC_HDF5_VAR_INFO_T *hdf5_v1;
1849 hdf5_v1 = (NC_HDF5_VAR_INFO_T *)v1->format_var_info;
1853 if (!(new_size = malloc(v1->ndims *
sizeof(hsize_t))))
1855 for (d1 = 0; d1 < v1->ndims; d1++)
1857 assert(v1->dim[d1] && v1->dim[d1]->hdr.id == v1->dimids[d1]);
1858 new_size[d1] = v1->dim[d1]->len;
1860 if (H5Dset_extent(hdf5_v1->hdf_datasetid, new_size) < 0)
1870 if (write_dimid && hdf5_dim->hdf_dimscaleid)
1871 if ((retval = write_netcdf4_dimid(hdf5_dim->hdf_dimscaleid, dim->hdr.id)))
1892 nc4_rec_write_metadata(NC_GRP_INFO_T *grp, nc_bool_t bad_coord_order)
1894 NC_DIM_INFO_T *dim = NULL;
1895 NC_VAR_INFO_T *var = NULL;
1896 NC_GRP_INFO_T *child_grp = NULL;
1897 int coord_varid = -1;
1903 assert(grp && grp->hdr.name &&
1904 ((NC_HDF5_GRP_INFO_T *)(grp->format_grp_info))->hdf_grpid);
1905 LOG((3,
"%s: grp->hdr.name %s, bad_coord_order %d", __func__, grp->hdr.name,
1909 if ((retval = write_attlist(grp->att,
NC_GLOBAL, grp)))
1914 dim = (NC_DIM_INFO_T *)ncindexith(grp->dim, dim_index);
1915 var = (NC_VAR_INFO_T *)ncindexith(grp->vars, var_index);
1922 nc_bool_t found_coord, wrote_coord;
1926 for (found_coord = NC_FALSE; dim && !found_coord; )
1928 if (!dim->coord_var)
1930 if ((retval = write_dim(dim, grp, bad_coord_order)))
1935 coord_varid = dim->coord_var->hdr.id;
1936 found_coord = NC_TRUE;
1938 dim = (NC_DIM_INFO_T *)ncindexith(grp->dim, ++dim_index);
1943 for (wrote_coord = NC_FALSE; var && !wrote_coord; )
1945 if ((retval = write_var(var, grp, bad_coord_order)))
1947 if (found_coord && var->hdr.id == coord_varid)
1948 wrote_coord = NC_TRUE;
1949 var = (NC_VAR_INFO_T *)ncindexith(grp->vars, ++var_index);
1954 if ((retval = attach_dimscales(grp)))
1958 for (i = 0; i < ncindexsize(grp->children); i++)
1960 child_grp = (NC_GRP_INFO_T *)ncindexith(grp->children, i);
1962 if ((retval = nc4_rec_write_metadata(child_grp, bad_coord_order)))
1978 nc4_rec_write_groups_types(NC_GRP_INFO_T *grp)
1980 NC_GRP_INFO_T *child_grp;
1981 NC_HDF5_GRP_INFO_T *hdf5_grp;
1982 NC_TYPE_INFO_T *type;
1986 assert(grp && grp->hdr.name && grp->format_grp_info);
1987 LOG((3,
"%s: grp->hdr.name %s", __func__, grp->hdr.name));
1990 hdf5_grp = (NC_HDF5_GRP_INFO_T *)grp->format_grp_info;
1993 if (!hdf5_grp->hdf_grpid)
1994 if ((retval = create_group(grp)))
2000 if ((retval = write_nc3_strict_att(hdf5_grp->hdf_grpid)))
2004 for(i=0;i<ncindexsize(grp->type);i++) {
2005 type = (NC_TYPE_INFO_T *)ncindexith(grp->type, i);
2007 if ((retval = commit_type(grp, type)))
2012 for(i=0;i<ncindexsize(grp->children);i++) {
2013 if((child_grp = (NC_GRP_INFO_T*)ncindexith(grp->children,i)) == NULL)
continue;
2014 if ((retval = nc4_rec_write_groups_types(child_grp)))
2034 nc4_rec_match_dimscales(NC_GRP_INFO_T *grp)
2042 assert(grp && grp->hdr.name);
2043 LOG((4,
"%s: grp->hdr.name %s", __func__, grp->hdr.name));
2046 for (i = 0; i < ncindexsize(grp->children); i++)
2048 g = (NC_GRP_INFO_T*)ncindexith(grp->children, i);
2050 if ((retval = nc4_rec_match_dimscales(g)))
2056 for (i = 0; i < ncindexsize(grp->vars); i++)
2058 NC_HDF5_VAR_INFO_T *hdf5_var;
2063 var = (NC_VAR_INFO_T*)ncindexith(grp->vars, i);
2064 assert(var && var->format_var_info);
2065 hdf5_var = (NC_HDF5_VAR_INFO_T *)var->format_var_info;
2083 for (d = 0; d < ndims; d++)
2085 if (var->dim[d] == NULL) {
2086 nc4_find_dim(grp, var->dimids[d], &var->dim[d], NULL);
2098 if (hdf5_var->dimscale_hdf5_objids)
2100 for (d = 0; d < var->ndims; d++)
2102 nc_bool_t finished = NC_FALSE;
2103 LOG((5,
"%s: var %s has dimscale info...", __func__, var->hdr.name));
2106 for (g = grp; g && !finished; g = g->parent)
2109 for (j = 0; j < ncindexsize(g->dim); j++)
2112 NC_HDF5_DIM_INFO_T *hdf5_dim;
2113 dim = (NC_DIM_INFO_T *)ncindexith(g->dim, j);
2114 assert(dim && dim->format_dim_info);
2115 hdf5_dim = (NC_HDF5_DIM_INFO_T *)dim->format_dim_info;
2119 if (hdf5_var->dimscale_hdf5_objids[d].fileno[0] == hdf5_dim->hdf5_objid.fileno[0] &&
2120 hdf5_var->dimscale_hdf5_objids[d].objno[0] == hdf5_dim->hdf5_objid.objno[0] &&
2121 hdf5_var->dimscale_hdf5_objids[d].fileno[1] == hdf5_dim->hdf5_objid.fileno[1] &&
2122 hdf5_var->dimscale_hdf5_objids[d].objno[1] == hdf5_dim->hdf5_objid.objno[1])
2124 LOG((4,
"%s: for dimension %d, found dim %s", __func__,
2126 var->dimids[d] = dim->hdr.id;
2133 LOG((5,
"%s: dimid for this dimscale is %d", __func__,
2134 var->type_info->hdr.id));
2141 hsize_t *h5dimlen = NULL, *h5dimlenmax = NULL;
2145 if ((spaceid = H5Dget_space(hdf5_var->hdf_datasetid)) < 0)
2151 if (!(h5dimlen = malloc(var->ndims *
sizeof(hsize_t))))
2153 if (!(h5dimlenmax = malloc(var->ndims *
sizeof(hsize_t))))
2158 if ((dataset_ndims = H5Sget_simple_extent_dims(spaceid, h5dimlen,
2159 h5dimlenmax)) < 0) {
2164 if (dataset_ndims != var->ndims) {
2173 if (H5Sget_simple_extent_type(spaceid) != H5S_SCALAR)
2178 if (H5Sclose(spaceid) < 0) {
2187 for (d = 0; d < var->ndims; d++)
2192 for(match=-1,k=0;k<ncindexsize(grp->dim);k++) {
2193 if((dim = (NC_DIM_INFO_T*)ncindexith(grp->dim,k)) == NULL)
continue;
2194 if ((dim->len == h5dimlen[d]) &&
2195 ((h5dimlenmax[d] == H5S_UNLIMITED && dim->unlimited) ||
2196 (h5dimlenmax[d] != H5S_UNLIMITED && !dim->unlimited)))
2204 sprintf(phony_dim_name,
"phony_dim_%d", grp->nc4_info->next_dimid);
2205 LOG((3,
"%s: creating phony dim for var %s", __func__, var->hdr.name));
2206 if ((retval = nc4_dim_list_add(grp, phony_dim_name, h5dimlen[d], -1, &dim)))
2213 if (!(dim->format_dim_info = calloc(1,
sizeof(NC_HDF5_DIM_INFO_T))))
2215 if (h5dimlenmax[d] == H5S_UNLIMITED)
2216 dim->unlimited = NC_TRUE;
2220 var->dimids[d] = dim->hdr.id;
2247 nc4_get_typeclass(
const NC_FILE_INFO_T *h5,
nc_type xtype,
int *type_class)
2251 LOG((4,
"%s xtype: %d", __func__, xtype));
2291 NC_TYPE_INFO_T *type;
2294 if ((retval = nc4_find_type(h5, xtype, &type)))
2299 *type_class = type->nc_type_class;
2318 reportobject(
int uselog, hid_t
id,
unsigned int type)
2320 char name[NC_HDF5_MAX_NAME];
2322 const char*
typename = NULL;
2323 long long printid = (
long long)
id;
2325 len = H5Iget_name(
id, name, NC_HDF5_MAX_NAME);
2330 case H5F_OBJ_FILE:
typename =
"File";
break;
2331 case H5F_OBJ_DATASET:
typename =
"Dataset";
break;
2332 case H5F_OBJ_GROUP:
typename =
"Group";
break;
2333 case H5F_OBJ_DATATYPE:
typename =
"Datatype";
break;
2335 typename =
"Attribute";
2336 len = H5Aget_name(
id, NC_HDF5_MAX_NAME, name);
2337 if(len < 0) len = 0;
2340 default:
typename =
"<unknown>";
break;
2344 LOG((0,
"Type = %s(%lld) name='%s'",
typename,printid,name));
2348 fprintf(stderr,
"Type = %s(%lld) name='%s'",
typename,printid,name);
2364 reportopenobjectsT(
int uselog, hid_t fid,
int ntypes,
unsigned int* otypes)
2368 size_t maxobjs = -1;
2369 hid_t* idlist = NULL;
2374 LOG((0,
"\nReport: open objects on %lld",(
long long)fid));
2377 fprintf(stdout,
"\nReport: open objects on %lld\n",(
long long)fid);
2378 maxobjs = H5Fget_obj_count(fid,H5F_OBJ_ALL);
2379 if(idlist != NULL) free(idlist);
2380 idlist = (hid_t*)malloc(
sizeof(hid_t)*maxobjs);
2381 for(t=0;t<ntypes;t++) {
2382 unsigned int ot = otypes[t];
2383 ocount = H5Fget_obj_ids(fid,ot,maxobjs,idlist);
2384 for(i=0;i<ocount;i++) {
2385 hid_t o = idlist[i];
2386 reportobject(uselog,o,ot);
2389 if(idlist != NULL) free(idlist);
2401 reportopenobjects(
int uselog, hid_t fid)
2403 unsigned int OTYPES[5] = {H5F_OBJ_FILE, H5F_OBJ_DATASET, H5F_OBJ_GROUP,
2404 H5F_OBJ_DATATYPE, H5F_OBJ_ATTR};
2406 reportopenobjectsT(uselog, fid ,5, OTYPES);
2417 showopenobjects5(NC_FILE_INFO_T* h5)
2419 NC_HDF5_FILE_INFO_T *hdf5_info;
2421 assert(h5 && h5->format_file_info);
2422 hdf5_info = (NC_HDF5_FILE_INFO_T *)h5->format_file_info;
2424 fprintf(stderr,
"===== begin showopenobjects =====\n");
2425 reportopenobjects(0,hdf5_info->hdfid);
2426 fprintf(stderr,
"===== end showopenobjects =====\n");
2439 showopenobjects(
int ncid)
2441 NC_FILE_INFO_T* h5 = NULL;
2444 if (nc4_find_nc_grp_h5(ncid, NULL, NULL, &h5) !=
NC_NOERR)
2445 fprintf(stderr,
"failed\n");
2447 showopenobjects5(h5);
2463 NC4_hdf5get_libversion(
unsigned* major,
unsigned* minor,
unsigned* release)
2465 if(H5get_libversion(major,minor,release) < 0)
2481 NC4_hdf5get_superblock(
struct NC_FILE_INFO* h5,
int* idp)
2483 NC_HDF5_FILE_INFO_T *hdf5_info;
2488 assert(h5 && h5->format_file_info);
2489 hdf5_info = (NC_HDF5_FILE_INFO_T *)h5->format_file_info;
2491 if((plist = H5Fget_create_plist(hdf5_info->hdfid)) < 0)
2493 if(H5Pget_version(plist, &super, NULL, NULL, NULL) < 0)
2495 if(idp) *idp = (int)super;
2497 if(plist >= 0) H5Pclose(plist);
2501 static int NC4_get_strict_att(NC_FILE_INFO_T*);
2502 static int NC4_walk(hid_t,
int*);
2529 NC4_isnetcdf4(
struct NC_FILE_INFO* h5)
2536 isnc4 = NC4_get_strict_att(h5);
2542 stat = NC4_walk(((NC_HDF5_GRP_INFO_T *)(h5->root_grp->format_grp_info))->hdf_grpid,
2547 isnc4 = (count >= 2);
2562 NC4_get_strict_att(NC_FILE_INFO_T *h5)
2568 grpid = ((NC_HDF5_GRP_INFO_T *)(h5->root_grp->format_grp_info))->hdf_grpid;
2571 attid = H5Aopen_name(grpid, NC3_STRICT_ATT_NAME);
2586 NC4_walk(hid_t gid,
int* countp)
2595 char name[NC_HDF5_MAX_NAME];
2598 err = H5Gget_num_objs(gid, &nobj);
2599 if(err < 0)
return err;
2601 for(i = 0; i < nobj; i++) {
2603 len = H5Gget_objname_by_idx(gid,(hsize_t)i,name,(
size_t)NC_HDF5_MAX_NAME);
2604 if(len < 0)
return len;
2606 otype = H5Gget_objtype_by_idx(gid,(
size_t)i);
2609 grpid = H5Gopen(gid,name);
2610 NC4_walk(grpid,countp);
2615 if(strcmp(name,
"phony_dim")==0)
2616 *countp = *countp + 1;
2617 dsid = H5Dopen(gid,name);
2618 na = H5Aget_num_attrs(dsid);
2619 for(j = 0; j < na; j++) {
2620 hid_t aid = H5Aopen_idx(dsid,(
unsigned int) j);
2622 const NC_reservedatt* ra;
2623 ssize_t len = H5Aget_name(aid, NC_HDF5_MAX_NAME, name);
2624 if(len < 0)
return len;
2627 ra = NC_findreserved(name);
2629 *countp = *countp + 1;
#define NC_ENOMEM
Memory allocation (malloc) failure.
#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_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_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