19 #include "nc4internal.h" 
   20 #include "ncdispatch.h" 
   21 #include "hdf5internal.h" 
   23 #include "hdf5debug.h" 
   26 #ifdef HAVE_INTTYPES_H 
   27 #define __STDC_FORMAT_MACROS 
   31 #define NC_HDF5_MAX_NAME 1024  
   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     hdf5_var = (NC_HDF5_VAR_INFO_T*)var->format_var_info;   
 
  106     assert(hdf5_var != NULL);
 
  107         for (d = 0; d < var->ndims; d++)
 
  109             if (var->dimids[d] == dimid && !hdf5_var->dimscale)
 
  111                 LOG((2, 
"%s: attaching scale for dimid %d to var %s",
 
  112                      __func__, var->dimids[d], var->hdr.name));
 
  115                     if (H5DSattach_scale(hdf5_var->hdf_datasetid,
 
  118                     hdf5_var->dimscale_attached[d] = NC_TRUE;
 
  143 rec_detach_scales(NC_GRP_INFO_T *grp, 
int dimid, hid_t dimscaleid)
 
  146     NC_GRP_INFO_T *child_grp;
 
  150     assert(grp && grp->hdr.name && dimid >= 0 && dimscaleid >= 0);
 
  151     LOG((3, 
"%s: grp->hdr.name %s", __func__, grp->hdr.name));
 
  154     for(i=0;i<ncindexsize(grp->children);i++) {
 
  155         child_grp = (NC_GRP_INFO_T*)ncindexith(grp->children,i);
 
  156         if(child_grp == NULL) 
continue;
 
  157         if ((retval = rec_detach_scales(child_grp, dimid, dimscaleid)))
 
  162     for (i = 0; i < ncindexsize(grp->vars); i++)
 
  164         NC_HDF5_VAR_INFO_T *hdf5_var;
 
  165         var = (NC_VAR_INFO_T*)ncindexith(grp->vars, i);
 
  166         assert(var && var->format_var_info);
 
  167         hdf5_var = (NC_HDF5_VAR_INFO_T *)var->format_var_info;
 
  169         for (d = 0; d < var->ndims; d++)
 
  171             if (var->dimids[d] == dimid && !hdf5_var->dimscale)
 
  173                 LOG((2, 
"%s: detaching scale for dimid %d to var %s",
 
  174                      __func__, var->dimids[d], var->hdr.name));
 
  177                     if (hdf5_var->dimscale_attached && hdf5_var->dimscale_attached[d])
 
  179                         if (H5DSdetach_scale(hdf5_var->hdf_datasetid,
 
  182                         hdf5_var->dimscale_attached[d] = NC_FALSE;
 
  203 nc4_open_var_grp2(NC_GRP_INFO_T *grp, 
int varid, hid_t *dataset)
 
  206     NC_HDF5_VAR_INFO_T *hdf5_var;
 
  208     assert(grp && grp->format_grp_info && dataset);
 
  211     if (!(var = (NC_VAR_INFO_T *)ncindexith(grp->vars, varid)))
 
  213     assert(var && var->hdr.id == varid && var->format_var_info);
 
  214     hdf5_var = (NC_HDF5_VAR_INFO_T *)var->format_var_info;
 
  217     if (!hdf5_var->hdf_datasetid)
 
  219         NC_HDF5_GRP_INFO_T *hdf5_grp;
 
  220         hdf5_grp = (NC_HDF5_GRP_INFO_T *)grp->format_grp_info;
 
  222         if ((hdf5_var->hdf_datasetid = H5Dopen2(hdf5_grp->hdf_grpid,
 
  223                                                 var->hdr.name, H5P_DEFAULT)) < 0)
 
  227     *dataset = hdf5_var->hdf_datasetid;
 
  250 nc4_get_hdf_typeid(NC_FILE_INFO_T *h5, 
nc_type xtype,
 
  251                    hid_t *hdf_typeid, 
int endianness)
 
  253     NC_TYPE_INFO_T *type;
 
  257     assert(hdf_typeid && h5);
 
  269             if ((
typeid = H5Tcopy(H5T_C_S1)) < 0)
 
  271             if (H5Tset_strpad(
typeid, H5T_STR_NULLTERM) < 0)
 
  273             if(H5Tset_cset(
typeid, H5T_CSET_ASCII) < 0)
 
  277             *hdf_typeid = 
typeid;
 
  282             if ((
typeid = H5Tcopy(H5T_C_S1)) < 0)
 
  284             if (H5Tset_size(
typeid, H5T_VARIABLE) < 0)
 
  286             if(H5Tset_cset(
typeid, H5T_CSET_UTF8) < 0)
 
  290             *hdf_typeid = 
typeid;
 
  301                 typeid = H5T_STD_I8LE;
 
  303                 typeid = H5T_STD_I8BE;
 
  305                 typeid = H5T_NATIVE_SCHAR;
 
  310                 typeid = H5T_STD_I16LE;
 
  312                 typeid = H5T_STD_I16BE;
 
  314                 typeid = H5T_NATIVE_SHORT;
 
  319                 typeid = H5T_STD_I32LE;
 
  321                 typeid = H5T_STD_I32BE;
 
  323                 typeid = H5T_NATIVE_INT;
 
  328                 typeid = H5T_STD_U8LE;
 
  330                 typeid = H5T_STD_U8BE;
 
  332                 typeid = H5T_NATIVE_UCHAR;
 
  337                 typeid = H5T_STD_U16LE;
 
  339                 typeid = H5T_STD_U16BE;
 
  341                 typeid = H5T_NATIVE_USHORT;
 
  346                 typeid = H5T_STD_U32LE;
 
  348                 typeid = H5T_STD_U32BE;
 
  350                 typeid = H5T_NATIVE_UINT;
 
  355                 typeid = H5T_STD_I64LE;
 
  357                 typeid = H5T_STD_I64BE;
 
  359                 typeid = H5T_NATIVE_LLONG;
 
  364                 typeid = H5T_STD_U64LE;
 
  366                 typeid = H5T_STD_U64BE;
 
  368                 typeid = H5T_NATIVE_ULLONG;
 
  373                 typeid = H5T_IEEE_F32LE;
 
  375                 typeid = H5T_IEEE_F32BE;
 
  377                 typeid = H5T_NATIVE_FLOAT;
 
  382                 typeid = H5T_IEEE_F64LE;
 
  384                 typeid = H5T_IEEE_F64BE;
 
  386                 typeid = H5T_NATIVE_DOUBLE;
 
  391             if (nc4_find_type(h5, xtype, &type))
 
  395             typeid = ((NC_HDF5_TYPE_INFO_T *)type->format_type_info)->hdf_typeid;
 
  401         if ((*hdf_typeid = H5Tcopy(
typeid)) < 0)
 
  405     assert(*hdf_typeid != -1);
 
  408     if (
typeid > 0 && H5Tclose(
typeid) < 0)
 
  428 put_att_grpa(NC_GRP_INFO_T *grp, 
int varid, NC_ATT_INFO_T *att)
 
  430     NC_HDF5_GRP_INFO_T *hdf5_grp;
 
  431     hid_t datasetid = 0, locid;
 
  432     hid_t attid = 0, spaceid = 0, file_typeid = 0;
 
  433     hid_t existing_att_typeid = 0, existing_attid = 0, existing_spaceid = 0;
 
  437     int phoney_data = 99;
 
  440     assert(att->hdr.name && grp && grp->format_grp_info);
 
  441     LOG((3, 
"%s: varid %d att->hdr.id %d att->hdr.name %s att->nc_typeid %d " 
  442          "att->len %d", __func__, varid, att->hdr.id, att->hdr.name,
 
  443          att->nc_typeid, att->len));
 
  446     hdf5_grp = (NC_HDF5_GRP_INFO_T *)grp->format_grp_info;
 
  449     if (grp->nc4_info->no_write)
 
  454         locid = hdf5_grp->hdf_grpid;
 
  457         if ((retval = nc4_open_var_grp2(grp, varid, &datasetid)))
 
  465     if ((retval = nc4_get_hdf_typeid(grp->nc4_info, att->nc_typeid,
 
  476     else if (att->stdata)
 
  488         size_t string_size = dims[0];
 
  492             if ((spaceid = H5Screate(H5S_NULL)) < 0)
 
  497             if ((spaceid = H5Screate(H5S_SCALAR)) < 0)
 
  500         if (H5Tset_size(file_typeid, string_size) < 0)
 
  502         if (H5Tset_strpad(file_typeid, H5T_STR_NULLTERM) < 0)
 
  509             if ((spaceid = H5Screate(H5S_NULL)) < 0)
 
  514             if ((spaceid = H5Screate_simple(1, dims, NULL)) < 0)
 
  520     if ((attr_exists = H5Aexists(locid, att->hdr.name)) < 0)
 
  527         if ((existing_attid = H5Aopen(locid, att->hdr.name, H5P_DEFAULT)) < 0)
 
  531         if ((existing_att_typeid = H5Aget_type(existing_attid)) < 0)
 
  535         if ((existing_spaceid = H5Aget_space(existing_attid)) < 0)
 
  537         if ((npoints = H5Sget_simple_extent_npoints(existing_spaceid)) < 0)
 
  542         if (!H5Tequal(file_typeid, existing_att_typeid) ||
 
  543             (att->nc_typeid != 
NC_CHAR && npoints != att->len))
 
  548             if (H5Adelete(locid, att->hdr.name) < 0)
 
  553             if ((attid = H5Acreate1(locid, att->hdr.name, file_typeid, spaceid,
 
  558             if (H5Awrite(attid, file_typeid, data) < 0)
 
  566             if (H5Awrite(existing_attid, file_typeid, data) < 0)
 
  575         if ((attid = H5Acreate1(locid, att->hdr.name, file_typeid, spaceid,
 
  580         if (H5Awrite(attid, file_typeid, data) < 0)
 
  585     if (file_typeid && H5Tclose(file_typeid))
 
  587     if (attid > 0 && H5Aclose(attid) < 0)
 
  589     if (existing_att_typeid && H5Tclose(existing_att_typeid))
 
  591     if (existing_attid > 0 && H5Aclose(existing_attid) < 0)
 
  593     if (spaceid > 0 && H5Sclose(spaceid) < 0)
 
  595     if (existing_spaceid > 0 && H5Sclose(existing_spaceid) < 0)
 
  612 write_attlist(NCindex *attlist, 
int varid, NC_GRP_INFO_T *grp)
 
  618     for(i = 0; i < ncindexsize(attlist); i++)
 
  620         att = (NC_ATT_INFO_T *)ncindexith(attlist, i);
 
  624             LOG((4, 
"%s: writing att %s to varid %d", __func__, att->hdr.name, varid));
 
  625             if ((retval = put_att_grpa(grp, varid, att)))
 
  627             att->dirty = NC_FALSE;
 
  628             att->created = NC_TRUE;
 
  648 write_coord_dimids(NC_VAR_INFO_T *var)
 
  650     NC_HDF5_VAR_INFO_T *hdf5_var;
 
  651     hsize_t coords_len[1];
 
  652     hid_t c_spaceid = -1, c_attid = -1;
 
  655     assert(var && var->format_var_info);
 
  658     hdf5_var = (NC_HDF5_VAR_INFO_T *)var->format_var_info;
 
  661     coords_len[0] = var->ndims;
 
  662     if ((c_spaceid = H5Screate_simple(1, coords_len, coords_len)) < 0)
 
  666     if ((c_attid = H5Acreate1(hdf5_var->hdf_datasetid, COORDINATES,
 
  667                              H5T_NATIVE_INT, c_spaceid, H5P_DEFAULT)) < 0)
 
  671     if (H5Awrite(c_attid, H5T_NATIVE_INT, var->dimids) < 0)
 
  675     if (c_spaceid >= 0 && H5Sclose(c_spaceid) < 0)
 
  677     if (c_attid >= 0 && H5Aclose(c_attid) < 0)
 
  693 write_netcdf4_dimid(hid_t datasetid, 
int dimid)
 
  695     hid_t dimid_spaceid = -1, dimid_attid = -1;
 
  700     if ((dimid_spaceid = H5Screate(H5S_SCALAR)) < 0)
 
  704     if ((attr_exists = H5Aexists(datasetid, NC_DIMID_ATT_NAME)) < 0)
 
  707         dimid_attid = H5Aopen_by_name(datasetid, 
".", NC_DIMID_ATT_NAME,
 
  708                                       H5P_DEFAULT, H5P_DEFAULT);
 
  711         dimid_attid = H5Acreate1(datasetid, NC_DIMID_ATT_NAME,
 
  712                                 H5T_NATIVE_INT, dimid_spaceid, H5P_DEFAULT);
 
  718     LOG((4, 
"%s: writing secret dimid %d", __func__, dimid));
 
  719     if (H5Awrite(dimid_attid, H5T_NATIVE_INT, &dimid) < 0)
 
  724     if (dimid_spaceid >= 0 && H5Sclose(dimid_spaceid) < 0)
 
  726     if (dimid_attid >= 0 && H5Aclose(dimid_attid) < 0)
 
  747 var_create_dataset(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var, nc_bool_t write_dimid)
 
  749     NC_HDF5_GRP_INFO_T *hdf5_grp;
 
  750     NC_HDF5_VAR_INFO_T *hdf5_var;
 
  751     hid_t plistid = 0, access_plistid = 0, 
typeid = 0, spaceid = 0;
 
  752     hsize_t chunksize[H5S_MAX_RANK], dimsize[H5S_MAX_RANK], maxdimsize[H5S_MAX_RANK];
 
  755     NC_DIM_INFO_T *dim = NULL;
 
  758     unsigned int* params = NULL;
 
  760     assert(grp && grp->format_grp_info && var && var->format_var_info);
 
  762     LOG((3, 
"%s:: name %s", __func__, var->hdr.name));
 
  765     hdf5_grp = (NC_HDF5_GRP_INFO_T *)grp->format_grp_info;
 
  766     hdf5_var = (NC_HDF5_VAR_INFO_T *)var->format_var_info;
 
  769     if ((plistid = H5Pcreate(H5P_DATASET_CREATE)) < 0)
 
  771     if ((access_plistid = H5Pcreate(H5P_DATASET_ACCESS)) < 0)
 
  775     if (H5Pset_obj_track_times(plistid, 0) < 0)
 
  779     if ((retval = nc4_get_hdf_typeid(grp->nc4_info, var->type_info->hdr.id, &
typeid,
 
  780                                      var->type_info->endianness)))
 
  787         if (H5Pset_fill_time(plistid, H5D_FILL_TIME_NEVER) < 0)
 
  792         if ((retval = nc4_get_fill_value(grp->nc4_info, var, &fillp)))
 
  798             if (var->type_info->nc_type_class == 
NC_STRING)
 
  800                 if (H5Pset_fill_value(plistid, 
typeid, fillp) < 0)
 
  809                 hid_t fill_typeid = 0;
 
  811                 if ((retval = nc4_get_hdf_typeid(grp->nc4_info, var->type_info->hdr.id, &fill_typeid,
 
  814                 if (H5Pset_fill_value(plistid, fill_typeid, fillp) < 0)
 
  816                     if (H5Tclose(fill_typeid) < 0)
 
  820                 if (H5Tclose(fill_typeid) < 0)
 
  829         if (H5Pset_fletcher32(plistid) < 0)
 
  834         if (H5Pset_shuffle(plistid) < 0)
 
  844     if(var->filters != NULL) {
 
  846     NClist* filters = (NClist*)var->filters;
 
  847     for(j=0;j<nclistlength(filters);j++) {
 
  848         struct NC_HDF5_Filter* fi = (
struct NC_HDF5_Filter*)nclistget(filters,j);
 
  850                 if(fi->filterid == H5Z_FILTER_DEFLATE) {
 
  854                     level = (int)fi->params[0];
 
  855                     if(H5Pset_deflate(plistid, level) < 0)
 
  857             } 
else if(fi->filterid == H5Z_FILTER_SZIP) {
 
  862                     options_mask = (int)fi->params[0];
 
  863                     bits_per_pixel = (
int)fi->params[1];
 
  864                     if(H5Pset_szip(plistid, options_mask, bits_per_pixel) < 0)
 
  867                     herr_t code = H5Pset_filter(plistid, fi->filterid,
 
  873                         fi->nparams, fi->params);
 
  890         for (d = 0; d < var->ndims; d++) {
 
  892             assert(dim && dim->hdr.id == var->dimids[d]);
 
  900         if (!var->shuffle && !var->fletcher32 && nclistlength((NClist*)var->filters) == 0 &&
 
  901             (var->chunksizes == NULL || !var->chunksizes[0]) && !unlimdim)
 
  906         for (d = 0; d < var->ndims; d++)
 
  909             assert(dim && dim->hdr.id == var->dimids[d]);
 
  910             dimsize[d] = dim->unlimited ? NC_HDF5_UNLIMITED_DIMSIZE : dim->len;
 
  911             maxdimsize[d] = dim->unlimited ? H5S_UNLIMITED : (hsize_t)dim->len;
 
  914                 if (var->chunksizes[d])
 
  915                     chunksize[d] = var->chunksizes[d];
 
  919                     if (var->type_info->nc_type_class == 
NC_STRING)
 
  920                         type_size = 
sizeof(
char *);
 
  922                         type_size = var->type_info->size;
 
  928                         chunksize[d] = pow((
double)DEFAULT_CHUNK_SIZE/type_size,
 
  929                                            1/(
double)(var->ndims - unlimdim));
 
  933                     if (!dim->unlimited && chunksize[d] > dim->len)
 
  934                         chunksize[d] = dim->len;
 
  937                     var->chunksizes[d] = chunksize[d];
 
  943         if ((spaceid = H5Screate_simple(var->ndims, dimsize, maxdimsize)) < 0)
 
  948         if ((spaceid = H5Screate(H5S_SCALAR)) < 0)
 
  957         if (H5Pset_layout(plistid, H5D_CONTIGUOUS) < 0)
 
  962         if (H5Pset_layout(plistid, H5D_COMPACT) < 0)
 
  967         if (H5Pset_chunk(plistid, var->ndims, chunksize) < 0)
 
  972     if (H5Pset_attr_creation_order(plistid, H5P_CRT_ORDER_TRACKED|
 
  973                                    H5P_CRT_ORDER_INDEXED) < 0)
 
  977     if (var->storage == 
NC_CHUNKED && var->chunk_cache_size)
 
  978         if (H5Pset_chunk_cache(access_plistid, var->chunk_cache_nelems,
 
  979                                var->chunk_cache_size, var->chunk_cache_preemption) < 0)
 
  983     name_to_use = var->alt_name ? var->alt_name : var->hdr.name;
 
  984     LOG((4, 
"%s: about to H5Dcreate2 dataset %s of type 0x%x", __func__,
 
  985          name_to_use, 
typeid));
 
  986     if ((hdf5_var->hdf_datasetid = H5Dcreate2(hdf5_grp->hdf_grpid, name_to_use, 
typeid,
 
  987                                               spaceid, H5P_DEFAULT, plistid, access_plistid)) < 0)
 
  989     var->created = NC_TRUE;
 
  990     var->is_new_var = NC_FALSE;
 
  996         if ((retval = write_coord_dimids(var)))
 
 1002     if (hdf5_var->dimscale)
 
 1004         if (H5DSset_scale(hdf5_var->hdf_datasetid, var->hdr.name) < 0)
 
 1015             if ((retval = write_netcdf4_dimid(hdf5_var->hdf_datasetid, var->dimids[0])))
 
 1020     if ((retval = write_attlist(var->att, var->hdr.id, grp)))
 
 1022     var->attr_dirty = NC_FALSE;
 
 1026     if (
typeid > 0 && H5Tclose(
typeid) < 0)
 
 1028     if (plistid > 0 && H5Pclose(plistid) < 0)
 
 1030     if (access_plistid > 0 && H5Pclose(access_plistid) < 0)
 
 1032     if (spaceid > 0 && H5Sclose(spaceid) < 0)
 
 1036         if (var->type_info->nc_type_class == 
NC_VLEN)
 
 1038         else if (var->type_info->nc_type_class == 
NC_STRING && *(
char **)fillp)
 
 1039             free(*(
char **)fillp);
 
 1060 nc4_adjust_var_cache(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var)
 
 1062     size_t chunk_size_bytes = 1;
 
 1070 #ifdef USE_PARALLEL4 
 1072     if (grp->nc4_info->parallel)
 
 1077     for (d = 0; d < var->ndims; d++)
 
 1078         chunk_size_bytes *= var->chunksizes[d];
 
 1079     if (var->type_info->size)
 
 1080         chunk_size_bytes *= var->type_info->size;
 
 1082         chunk_size_bytes *= 
sizeof(
char *);
 
 1087     if (var->chunk_cache_size == CHUNK_CACHE_SIZE)
 
 1088         if (chunk_size_bytes > var->chunk_cache_size)
 
 1090             var->chunk_cache_size = chunk_size_bytes * DEFAULT_CHUNKS_IN_CACHE;
 
 1091             if (var->chunk_cache_size > MAX_DEFAULT_CACHE_SIZE)
 
 1092                 var->chunk_cache_size = MAX_DEFAULT_CACHE_SIZE;
 
 1093             if ((retval = nc4_reopen_dataset(grp, var)))
 
 1116 commit_type(NC_GRP_INFO_T *grp, NC_TYPE_INFO_T *type)
 
 1118     NC_HDF5_GRP_INFO_T *hdf5_grp;
 
 1119     NC_HDF5_TYPE_INFO_T *hdf5_type;
 
 1120     hid_t base_hdf_typeid;
 
 1123     assert(grp && grp->format_grp_info && type && type->format_type_info);
 
 1126     hdf5_grp = (NC_HDF5_GRP_INFO_T *)grp->format_grp_info;
 
 1127     hdf5_type = (NC_HDF5_TYPE_INFO_T *)type->format_type_info;
 
 1130     if (type->committed)
 
 1136         NC_FIELD_INFO_T *field;
 
 1137         hid_t hdf_base_typeid, hdf_typeid;
 
 1140         if ((hdf5_type->hdf_typeid = H5Tcreate(H5T_COMPOUND, type->size)) < 0)
 
 1142         LOG((4, 
"creating compound type %s hdf_typeid 0x%x", type->hdr.name,
 
 1143              hdf5_type->hdf_typeid));
 
 1145         for(i=0;i<nclistlength(type->u.c.field);i++)
 
 1147             field = (NC_FIELD_INFO_T *)nclistget(type->u.c.field, i);
 
 1149             if ((retval = nc4_get_hdf_typeid(grp->nc4_info, field->nc_typeid,
 
 1150                                              &hdf_base_typeid, type->endianness)))
 
 1159                 for (d = 0; d < field->ndims; d++)
 
 1160                     dims[d] = field->dim_size[d];
 
 1161                 if ((hdf_typeid = H5Tarray_create1(hdf_base_typeid, field->ndims,
 
 1164                     if (H5Tclose(hdf_base_typeid) < 0)
 
 1168                 if (H5Tclose(hdf_base_typeid) < 0)
 
 1172                 hdf_typeid = hdf_base_typeid;
 
 1173             LOG((4, 
"inserting field %s offset %d hdf_typeid 0x%x", field->hdr.name,
 
 1174                  field->offset, hdf_typeid));
 
 1175             if (H5Tinsert(hdf5_type->hdf_typeid, field->hdr.name, field->offset,
 
 1178             if (H5Tclose(hdf_typeid) < 0)
 
 1182     else if (type->nc_type_class == 
NC_VLEN)
 
 1185         if ((retval = nc4_get_hdf_typeid(grp->nc4_info, type->u.v.base_nc_typeid,
 
 1186                                          &base_hdf_typeid, type->endianness)))
 
 1190         if ((hdf5_type->hdf_typeid = H5Tvlen_create(base_hdf_typeid)) < 0)
 
 1193     else if (type->nc_type_class == 
NC_OPAQUE)
 
 1196         if ((hdf5_type->hdf_typeid = H5Tcreate(H5T_OPAQUE, type->size)) < 0)
 
 1199     else if (type->nc_type_class == 
NC_ENUM)
 
 1201         NC_ENUM_MEMBER_INFO_T *enum_m;
 
 1204         if (nclistlength(type->u.e.enum_member) == 0)
 
 1208         if ((retval = nc4_get_hdf_typeid(grp->nc4_info, type->u.e.base_nc_typeid,
 
 1209                                          &base_hdf_typeid, type->endianness)))
 
 1213         if ((hdf5_type->hdf_typeid =  H5Tenum_create(base_hdf_typeid)) < 0)
 
 1217         for(i=0;i<nclistlength(type->u.e.enum_member);i++) {
 
 1218             enum_m = (NC_ENUM_MEMBER_INFO_T*)nclistget(type->u.e.enum_member,i);
 
 1219             if (H5Tenum_insert(hdf5_type->hdf_typeid, enum_m->name, enum_m->value) < 0)
 
 1225         LOG((0, 
"Unknown class: %d", type->nc_type_class));
 
 1230     if (H5Tcommit1(hdf5_grp->hdf_grpid, type->hdr.name, hdf5_type->hdf_typeid) < 0)
 
 1232     type->committed = NC_TRUE;
 
 1233     LOG((4, 
"just committed type %s, HDF typeid: 0x%x", type->hdr.name,
 
 1234          hdf5_type->hdf_typeid));
 
 1239     if ((hdf5_type->native_hdf_typeid = H5Tget_native_type(hdf5_type->hdf_typeid,
 
 1240                                                            H5T_DIR_DEFAULT)) < 0)
 
 1257 write_nc3_strict_att(hid_t hdf_grpid)
 
 1259     hid_t attid = 0, spaceid = 0;
 
 1266     if ((attr_exists = H5Aexists(hdf_grpid, NC3_STRICT_ATT_NAME)) < 0)
 
 1273     if ((spaceid = H5Screate(H5S_SCALAR)) < 0)
 
 1275     if ((attid = H5Acreate1(hdf_grpid, NC3_STRICT_ATT_NAME,
 
 1276                            H5T_NATIVE_INT, spaceid, H5P_DEFAULT)) < 0)
 
 1278     if (H5Awrite(attid, H5T_NATIVE_INT, &one) < 0)
 
 1282     if (spaceid > 0 && (H5Sclose(spaceid) < 0))
 
 1284     if (attid > 0 && (H5Aclose(attid) < 0))
 
 1302 create_group(NC_GRP_INFO_T *grp)
 
 1304     NC_HDF5_GRP_INFO_T *hdf5_grp, *parent_hdf5_grp;
 
 1308     assert(grp && grp->format_grp_info && grp->parent &&
 
 1309            grp->parent->format_grp_info);
 
 1312     hdf5_grp = (NC_HDF5_GRP_INFO_T *)grp->format_grp_info;
 
 1313     parent_hdf5_grp = (NC_HDF5_GRP_INFO_T *)grp->parent->format_grp_info;
 
 1314     assert(parent_hdf5_grp->hdf_grpid);
 
 1318     if ((gcpl_id = H5Pcreate(H5P_GROUP_CREATE)) < 0)
 
 1322     if (H5Pset_obj_track_times(gcpl_id, 0) < 0)
 
 1326     if (H5Pset_link_creation_order(gcpl_id, H5P_CRT_ORDER_TRACKED|H5P_CRT_ORDER_INDEXED) < 0)
 
 1330     if (H5Pset_attr_creation_order(gcpl_id, H5P_CRT_ORDER_TRACKED|H5P_CRT_ORDER_INDEXED) < 0)
 
 1334     if ((hdf5_grp->hdf_grpid = H5Gcreate2(parent_hdf5_grp->hdf_grpid, grp->hdr.name,
 
 1335                                           H5P_DEFAULT, gcpl_id, H5P_DEFAULT)) < 0)
 
 1339     if (gcpl_id > -1 && H5Pclose(gcpl_id) < 0)
 
 1342         if (hdf5_grp->hdf_grpid > 0 && H5Gclose(hdf5_grp->hdf_grpid) < 0)
 
 1359 attach_dimscales(NC_GRP_INFO_T *grp)
 
 1362     NC_HDF5_VAR_INFO_T *hdf5_var;
 
 1366     for (v = 0; v < ncindexsize(grp->vars); v++)
 
 1369         var = (NC_VAR_INFO_T *)ncindexith(grp->vars, v);
 
 1370         assert(var && var->format_var_info);
 
 1371         hdf5_var = (NC_HDF5_VAR_INFO_T *)var->format_var_info;
 
 1375         if (hdf5_var->dimscale)
 
 1379         for (d = 0; d < var->ndims; d++)
 
 1382             if (hdf5_var->dimscale_attached)
 
 1384                 if (!hdf5_var->dimscale_attached[d])
 
 1387                     assert(var->dim[d] && var->dim[d]->hdr.id == var->dimids[d] &&
 
 1388                            var->dim[d]->format_dim_info);
 
 1390                     LOG((2, 
"%s: attaching scale for dimid %d to var %s",
 
 1391                          __func__, var->dimids[d], var->hdr.name));
 
 1394                     if (var->dim[d]->coord_var)
 
 1395                         dsid = ((NC_HDF5_VAR_INFO_T *)(var->dim[d]->coord_var->format_var_info))->hdf_datasetid;
 
 1397                         dsid = ((NC_HDF5_DIM_INFO_T *)var->dim[d]->format_dim_info)->hdf_dimscaleid;
 
 1401                     if (H5DSattach_scale(hdf5_var->hdf_datasetid, dsid, d) < 0)
 
 1403                     hdf5_var->dimscale_attached[d] = NC_TRUE;
 
 1423 var_exists(hid_t grpid, 
char *name, nc_bool_t *exists)
 
 1431     if ((link_exists = H5Lexists(grpid, name, H5P_DEFAULT)) < 0)
 
 1438         if (H5Gget_objinfo(grpid, name, 1, &statbuf) < 0)
 
 1441         if (H5G_DATASET == statbuf.type)
 
 1464 remove_coord_atts(hid_t hdf_datasetid)
 
 1470     if ((attr_exists = H5Aexists(hdf_datasetid, NC_DIMID_ATT_NAME)) < 0)
 
 1474         if (H5Adelete(hdf_datasetid, NC_DIMID_ATT_NAME) < 0)
 
 1479     if ((attr_exists = H5Aexists(hdf_datasetid,
 
 1480                                  HDF5_DIMSCALE_CLASS_ATT_NAME)) < 0)
 
 1484         if (H5Adelete(hdf_datasetid, HDF5_DIMSCALE_CLASS_ATT_NAME) < 0)
 
 1487     if ((attr_exists = H5Aexists(hdf_datasetid,
 
 1488                                  HDF5_DIMSCALE_NAME_ATT_NAME)) < 0)
 
 1492         if (H5Adelete(hdf_datasetid, HDF5_DIMSCALE_NAME_ATT_NAME) < 0)
 
 1513 write_var(NC_VAR_INFO_T *var, NC_GRP_INFO_T *grp, nc_bool_t write_dimid)
 
 1515     NC_HDF5_GRP_INFO_T *hdf5_grp;
 
 1516     NC_HDF5_VAR_INFO_T *hdf5_var;
 
 1517     nc_bool_t replace_existing_var = NC_FALSE;
 
 1520     assert(var && var->format_var_info && grp && grp->format_grp_info);
 
 1522     LOG((4, 
"%s: writing var %s", __func__, var->hdr.name));
 
 1525     hdf5_grp = (NC_HDF5_GRP_INFO_T *)grp->format_grp_info;
 
 1526     hdf5_var = (NC_HDF5_VAR_INFO_T *)var->format_var_info;
 
 1530     if (var->created && var->fill_val_changed)
 
 1532         replace_existing_var = NC_TRUE;
 
 1533         var->fill_val_changed = NC_FALSE;
 
 1539         flag_atts_dirty(var->att);
 
 1546     if (var->became_coord_var)
 
 1548         if ((NC_DIM_INFO_T *)ncindexlookup(grp->dim, var->hdr.name))
 
 1552             if ((retval = var_exists(hdf5_grp->hdf_grpid, var->hdr.name, &exists)))
 
 1558                 replace_existing_var = NC_TRUE;
 
 1559                 flag_atts_dirty(var->att);
 
 1566     if (replace_existing_var)
 
 1571         if ((d1 = (NC_DIM_INFO_T *)ncindexlookup(grp->dim, var->hdr.name)))
 
 1574             assert(d1->format_dim_info && d1->hdr.name);
 
 1576             if ((retval = var_exists(hdf5_grp->hdf_grpid, var->hdr.name, &exists)))
 
 1584                     dsid = ((NC_HDF5_VAR_INFO_T *)d1->coord_var->format_var_info)->hdf_datasetid;
 
 1586                     dsid = ((NC_HDF5_DIM_INFO_T *)d1->format_dim_info)->hdf_dimscaleid;
 
 1592                 if ((retval = rec_detach_scales(grp->nc4_info->root_grp,
 
 1593                                                 var->dimids[0], dsid)))
 
 1601     if (var->was_coord_var && hdf5_var->dimscale_attached)
 
 1608             if ((retval = remove_coord_atts(hdf5_var->hdf_datasetid)))
 
 1612         for (d = 0; d < var->ndims; d++)
 
 1614             if (hdf5_var->dimscale_attached[d])
 
 1617                 assert(var->dim[d] && var->dim[d]->hdr.id == var->dimids[d] &&
 
 1618                        var->dim[d]->format_dim_info);
 
 1621                 if (var->dim[d]->coord_var)
 
 1622                     dsid = ((NC_HDF5_VAR_INFO_T *)var->dim[d]->coord_var->format_var_info)->hdf_datasetid;
 
 1624                     dsid = ((NC_HDF5_DIM_INFO_T *)var->dim[d]->format_dim_info)->hdf_dimscaleid;
 
 1628                 if (H5DSdetach_scale(hdf5_var->hdf_datasetid, dsid, d) < 0)
 
 1630                 hdf5_var->dimscale_attached[d] = NC_FALSE;
 
 1636     if (replace_existing_var)
 
 1639         if (hdf5_var->hdf_datasetid && H5Dclose(hdf5_var->hdf_datasetid) < 0)
 
 1641         hdf5_var->hdf_datasetid = 0;
 
 1644         if (H5Gunlink(hdf5_grp->hdf_grpid, var->hdr.name) < 0)
 
 1649     if (var->is_new_var || replace_existing_var)
 
 1651         if ((retval = var_create_dataset(grp, var, write_dimid)))
 
 1656         if (write_dimid && var->ndims)
 
 1657             if ((retval = write_netcdf4_dimid(hdf5_var->hdf_datasetid,
 
 1662     if (replace_existing_var)
 
 1666         if(hdf5_var->dimscale)
 
 1668             if ((retval = rec_reattach_scales(grp->nc4_info->root_grp,
 
 1669                                               var->dimids[0], hdf5_var->hdf_datasetid)))
 
 1676             if (hdf5_var->dimscale_attached)
 
 1677                 memset(hdf5_var->dimscale_attached, 0, 
sizeof(nc_bool_t) * var->ndims);
 
 1682     var->was_coord_var = NC_FALSE;
 
 1683     var->became_coord_var = NC_FALSE;
 
 1686     if (var->attr_dirty)
 
 1689         if ((retval = write_attlist(var->att, var->hdr.id, grp)))
 
 1691         var->attr_dirty = NC_FALSE;
 
 1711 nc4_create_dim_wo_var(NC_DIM_INFO_T *dim)
 
 1713     NC_HDF5_DIM_INFO_T *hdf5_dim;
 
 1714     NC_HDF5_GRP_INFO_T *hdf5_grp;
 
 1715     hid_t spaceid = -1, create_propid = -1;
 
 1716     hsize_t dims[1], max_dims[1], chunk_dims[1] = {1};
 
 1720     LOG((4, 
"%s: creating dim %s", __func__, dim->hdr.name));
 
 1723     assert(!dim->coord_var);
 
 1726     hdf5_grp = (NC_HDF5_GRP_INFO_T *)dim->container->format_grp_info;
 
 1727     hdf5_dim = (NC_HDF5_DIM_INFO_T *)dim->format_dim_info;
 
 1730     if ((create_propid = H5Pcreate(H5P_DATASET_CREATE)) < 0)
 
 1734     if (H5Pset_obj_track_times(create_propid, 0) < 0)
 
 1739     max_dims[0] = dim->len;
 
 1745         max_dims[0] = H5S_UNLIMITED;
 
 1746         if (H5Pset_chunk(create_propid, 1, chunk_dims) < 0)
 
 1751     if ((spaceid = H5Screate_simple(1, dims, max_dims)) < 0)
 
 1755     if (H5Pset_attr_creation_order(create_propid, H5P_CRT_ORDER_TRACKED|
 
 1756                                    H5P_CRT_ORDER_INDEXED) < 0)
 
 1760     LOG((4, 
"%s: about to H5Dcreate1 a dimscale dataset %s", __func__,
 
 1762     if ((hdf5_dim->hdf_dimscaleid = H5Dcreate2(hdf5_grp->hdf_grpid, dim->hdr.name,
 
 1763                                                H5T_IEEE_F32BE, spaceid,
 
 1764                                                H5P_DEFAULT, create_propid,
 
 1771     sprintf(dimscale_wo_var, 
"%s%10d", DIM_WITHOUT_VARIABLE, (
int)dim->len);
 
 1772     if (H5DSset_scale(hdf5_dim->hdf_dimscaleid, dimscale_wo_var) < 0)
 
 1778     if ((retval = write_netcdf4_dimid(hdf5_dim->hdf_dimscaleid, dim->hdr.id)))
 
 1782     if (spaceid > 0 && H5Sclose(spaceid) < 0)
 
 1784     if (create_propid > 0 && H5Pclose(create_propid) < 0)
 
 1802 write_dim(NC_DIM_INFO_T *dim, NC_GRP_INFO_T *grp, nc_bool_t write_dimid)
 
 1804     NC_HDF5_DIM_INFO_T *hdf5_dim;
 
 1807     assert(dim && dim->format_dim_info && grp && grp->format_grp_info);
 
 1810     hdf5_dim = (NC_HDF5_DIM_INFO_T *)dim->format_dim_info;
 
 1816     if (!hdf5_dim->hdf_dimscaleid)
 
 1817         if ((retval = nc4_create_dim_wo_var(dim)))
 
 1823         NC_VAR_INFO_T *v1 = NULL;
 
 1825         assert(dim->unlimited);
 
 1829         v1 = dim->coord_var;
 
 1832             NC_HDF5_VAR_INFO_T *hdf5_v1;
 
 1836             hdf5_v1 = (NC_HDF5_VAR_INFO_T *)v1->format_var_info;
 
 1840             if (!(new_size = malloc(v1->ndims * 
sizeof(hsize_t))))
 
 1842             for (d1 = 0; d1 < v1->ndims; d1++)
 
 1844                 assert(v1->dim[d1] && v1->dim[d1]->hdr.id == v1->dimids[d1]);
 
 1845                 new_size[d1] = v1->dim[d1]->len;
 
 1847             if (H5Dset_extent(hdf5_v1->hdf_datasetid, new_size) < 0)
 
 1857     if (write_dimid && hdf5_dim->hdf_dimscaleid)
 
 1858         if ((retval = write_netcdf4_dimid(hdf5_dim->hdf_dimscaleid, dim->hdr.id)))
 
 1879 nc4_rec_write_metadata(NC_GRP_INFO_T *grp, nc_bool_t bad_coord_order)
 
 1881     NC_DIM_INFO_T *dim = NULL;
 
 1882     NC_VAR_INFO_T *var = NULL;
 
 1883     NC_GRP_INFO_T *child_grp = NULL;
 
 1884     int coord_varid = -1;
 
 1890     assert(grp && grp->hdr.name &&
 
 1891            ((NC_HDF5_GRP_INFO_T *)(grp->format_grp_info))->hdf_grpid);
 
 1892     LOG((3, 
"%s: grp->hdr.name %s, bad_coord_order %d", __func__, grp->hdr.name,
 
 1896     if ((retval = write_attlist(grp->att, 
NC_GLOBAL, grp)))
 
 1901     dim = (NC_DIM_INFO_T *)ncindexith(grp->dim, dim_index);
 
 1902     var = (NC_VAR_INFO_T *)ncindexith(grp->vars, var_index);
 
 1909         nc_bool_t found_coord, wrote_coord;
 
 1913         for (found_coord = NC_FALSE; dim && !found_coord; )
 
 1915             if (!dim->coord_var)
 
 1917                 if ((retval = write_dim(dim, grp, bad_coord_order)))
 
 1922                 coord_varid = dim->coord_var->hdr.id;
 
 1923                 found_coord = NC_TRUE;
 
 1925             dim = (NC_DIM_INFO_T *)ncindexith(grp->dim, ++dim_index);
 
 1930         for (wrote_coord = NC_FALSE; var && !wrote_coord; )
 
 1932             if ((retval = write_var(var, grp, bad_coord_order)))
 
 1934             if (found_coord && var->hdr.id == coord_varid)
 
 1935                 wrote_coord = NC_TRUE;
 
 1936             var = (NC_VAR_INFO_T *)ncindexith(grp->vars, ++var_index);
 
 1941     if ((retval = attach_dimscales(grp)))
 
 1945     for (i = 0; i < ncindexsize(grp->children); i++)
 
 1947         child_grp = (NC_GRP_INFO_T *)ncindexith(grp->children, i);
 
 1949         if ((retval = nc4_rec_write_metadata(child_grp, bad_coord_order)))
 
 1965 nc4_rec_write_groups_types(NC_GRP_INFO_T *grp)
 
 1967     NC_GRP_INFO_T *child_grp;
 
 1968     NC_HDF5_GRP_INFO_T *hdf5_grp;
 
 1969     NC_TYPE_INFO_T *type;
 
 1973     assert(grp && grp->hdr.name && grp->format_grp_info);
 
 1974     LOG((3, 
"%s: grp->hdr.name %s", __func__, grp->hdr.name));
 
 1977     hdf5_grp = (NC_HDF5_GRP_INFO_T *)grp->format_grp_info;
 
 1980     if (!hdf5_grp->hdf_grpid)
 
 1981         if ((retval = create_group(grp)))
 
 1987         if ((retval = write_nc3_strict_att(hdf5_grp->hdf_grpid)))
 
 1991     for(i=0;i<ncindexsize(grp->type);i++) {
 
 1992         type = (NC_TYPE_INFO_T *)ncindexith(grp->type, i);
 
 1994         if ((retval = commit_type(grp, type)))
 
 1999     for(i=0;i<ncindexsize(grp->children);i++) {
 
 2000         if((child_grp = (NC_GRP_INFO_T*)ncindexith(grp->children,i)) == NULL) 
continue;
 
 2001         if ((retval = nc4_rec_write_groups_types(child_grp)))
 
 2021 nc4_rec_match_dimscales(NC_GRP_INFO_T *grp)
 
 2029     assert(grp && grp->hdr.name);
 
 2030     LOG((4, 
"%s: grp->hdr.name %s", __func__, grp->hdr.name));
 
 2033     for (i = 0; i < ncindexsize(grp->children); i++)
 
 2035         g = (NC_GRP_INFO_T*)ncindexith(grp->children, i);
 
 2037         if ((retval = nc4_rec_match_dimscales(g)))
 
 2043     for (i = 0; i < ncindexsize(grp->vars); i++)
 
 2045         NC_HDF5_VAR_INFO_T *hdf5_var;
 
 2050         var = (NC_VAR_INFO_T*)ncindexith(grp->vars, i);
 
 2051         assert(var && var->format_var_info);
 
 2052         hdf5_var = (NC_HDF5_VAR_INFO_T *)var->format_var_info;
 
 2070         for (d = 0; d < ndims; d++)
 
 2072             if (var->dim[d] == NULL) {
 
 2073                 nc4_find_dim(grp, var->dimids[d], &var->dim[d], NULL);
 
 2079         if (!hdf5_var->dimscale)
 
 2085             if (hdf5_var->dimscale_hdf5_objids)
 
 2087                 for (d = 0; d < var->ndims; d++)
 
 2089                     nc_bool_t finished = NC_FALSE;
 
 2090                     LOG((5, 
"%s: var %s has dimscale info...", __func__, var->hdr.name));
 
 2093                     for (g = grp; g && !finished; g = g->parent)
 
 2096                         for (j = 0; j < ncindexsize(g->dim); j++)
 
 2099                             NC_HDF5_DIM_INFO_T *hdf5_dim;
 
 2100                             dim = (NC_DIM_INFO_T *)ncindexith(g->dim, j);
 
 2101                             assert(dim && dim->format_dim_info);
 
 2102                             hdf5_dim = (NC_HDF5_DIM_INFO_T *)dim->format_dim_info;
 
 2106 #
if H5_VERSION_GE(1,12,0)
 
 2108                             if (H5Otoken_cmp(hdf5_var->hdf_datasetid, &hdf5_var->dimscale_hdf5_objids[d].token, &hdf5_dim->hdf5_objid.token, &token_cmp) < 0)
 
 2111                             if (hdf5_var->dimscale_hdf5_objids[d].fileno == hdf5_dim->hdf5_objid.fileno &&
 
 2114                             if (hdf5_var->dimscale_hdf5_objids[d].fileno[0] == hdf5_dim->hdf5_objid.fileno[0] &&
 
 2115                                 hdf5_var->dimscale_hdf5_objids[d].objno[0] == hdf5_dim->hdf5_objid.objno[0] &&
 
 2116                                 hdf5_var->dimscale_hdf5_objids[d].fileno[1] == hdf5_dim->hdf5_objid.fileno[1] &&
 
 2117                                 hdf5_var->dimscale_hdf5_objids[d].objno[1] == hdf5_dim->hdf5_objid.objno[1])
 
 2120                                 LOG((4, 
"%s: for dimension %d, found dim %s", __func__,
 
 2122                                 var->dimids[d] = dim->hdr.id;
 
 2129                     LOG((5, 
"%s: dimid for this dimscale is %d", __func__,
 
 2130                          var->type_info->hdr.id));
 
 2137                 hsize_t *h5dimlen = NULL, *h5dimlenmax = NULL;
 
 2141                 if ((spaceid = H5Dget_space(hdf5_var->hdf_datasetid)) < 0)
 
 2147                     if (!(h5dimlen = malloc(var->ndims * 
sizeof(hsize_t))))
 
 2149                     if (!(h5dimlenmax = malloc(var->ndims * 
sizeof(hsize_t))))
 
 2154                     if ((dataset_ndims = H5Sget_simple_extent_dims(spaceid, h5dimlen,
 
 2155                                                                    h5dimlenmax)) < 0) {
 
 2160                     if (dataset_ndims != var->ndims) {
 
 2169                     if (H5Sget_simple_extent_type(spaceid) != H5S_SCALAR)
 
 2174                 if (H5Sclose(spaceid) < 0) {
 
 2183                 for (d = 0; d < var->ndims; d++)
 
 2188                     for(match=-1,k=0;k<ncindexsize(grp->dim);k++) {
 
 2189                         if((dim = (NC_DIM_INFO_T*)ncindexith(grp->dim,k)) == NULL) 
continue;
 
 2190                         if ((dim->len == h5dimlen[d]) &&
 
 2191                             ((h5dimlenmax[d] == H5S_UNLIMITED && dim->unlimited) ||
 
 2192                              (h5dimlenmax[d] != H5S_UNLIMITED && !dim->unlimited)))
 
 2200                         sprintf(phony_dim_name, 
"phony_dim_%d", grp->nc4_info->next_dimid);
 
 2201                         LOG((3, 
"%s: creating phony dim for var %s", __func__, var->hdr.name));
 
 2202                         if ((retval = nc4_dim_list_add(grp, phony_dim_name, h5dimlen[d], -1, &dim)))
 
 2209                         if (!(dim->format_dim_info = calloc(1, 
sizeof(NC_HDF5_DIM_INFO_T))))
 
 2211                         if (h5dimlenmax[d] == H5S_UNLIMITED)
 
 2212                             dim->unlimited = NC_TRUE;
 
 2216                     var->dimids[d] = dim->hdr.id;
 
 2242 reportobject(
int uselog, hid_t 
id, 
unsigned int type)
 
 2244     char name[NC_HDF5_MAX_NAME];
 
 2246     const char* 
typename = NULL;
 
 2247     long long printid = (
long long)
id;
 
 2249     len = H5Iget_name(
id, name, NC_HDF5_MAX_NAME);
 
 2254     case H5F_OBJ_FILE: 
typename = 
"File"; 
break;
 
 2255     case H5F_OBJ_DATASET: 
typename = 
"Dataset"; 
break;
 
 2256     case H5F_OBJ_GROUP: 
typename = 
"Group"; 
break;
 
 2257     case H5F_OBJ_DATATYPE: 
typename = 
"Datatype"; 
break;
 
 2259         typename = 
"Attribute";
 
 2260         len = H5Aget_name(
id, NC_HDF5_MAX_NAME, name);
 
 2261         if(len < 0) len = 0;
 
 2264     default: 
typename = 
"<unknown>"; 
break;
 
 2268         LOG((0,
"Type = %s(%lld) name='%s'",
typename,printid,name));
 
 2272         fprintf(stderr,
"Type = %s(%lld) name='%s'",
typename,printid,name);
 
 2288 reportopenobjectsT(
int uselog, hid_t fid, 
int ntypes, 
unsigned int* otypes)
 
 2292     size_t maxobjs = -1;
 
 2293     hid_t* idlist = NULL;
 
 2298         LOG((0,
"\nReport: open objects on %lld",(
long long)fid));
 
 2301         fprintf(stdout,
"\nReport: open objects on %lld\n",(
long long)fid);
 
 2302     maxobjs = H5Fget_obj_count(fid,H5F_OBJ_ALL);
 
 2303     if(idlist != NULL) free(idlist);
 
 2304     idlist = (hid_t*)malloc(
sizeof(hid_t)*maxobjs);
 
 2305     for(t=0;t<ntypes;t++) {
 
 2306         unsigned int ot = otypes[t];
 
 2307         ocount = H5Fget_obj_ids(fid,ot,maxobjs,idlist);
 
 2308         for(i=0;i<ocount;i++) {
 
 2309             hid_t o = idlist[i];
 
 2310             reportobject(uselog,o,ot);
 
 2313     if(idlist != NULL) free(idlist);
 
 2325 reportopenobjects(
int uselog, hid_t fid)
 
 2327     unsigned int OTYPES[5] = {H5F_OBJ_FILE, H5F_OBJ_DATASET, H5F_OBJ_GROUP,
 
 2328                               H5F_OBJ_DATATYPE, H5F_OBJ_ATTR};
 
 2330     reportopenobjectsT(uselog, fid ,5, OTYPES);
 
 2341 showopenobjects5(NC_FILE_INFO_T* h5)
 
 2343     NC_HDF5_FILE_INFO_T *hdf5_info;
 
 2345     assert(h5 && h5->format_file_info);
 
 2346     hdf5_info = (NC_HDF5_FILE_INFO_T *)h5->format_file_info;
 
 2348     fprintf(stderr,
"===== begin showopenobjects =====\n");
 
 2349     reportopenobjects(0,hdf5_info->hdfid);
 
 2350     fprintf(stderr,
"===== end showopenobjects =====\n");
 
 2363 showopenobjects(
int ncid)
 
 2365     NC_FILE_INFO_T* h5 = NULL;
 
 2368     if (nc4_find_nc_grp_h5(ncid, NULL, NULL, &h5) != 
NC_NOERR)
 
 2369         fprintf(stderr,
"failed\n");
 
 2371         showopenobjects5(h5);
 
 2387 NC4_hdf5get_libversion(
unsigned* major,
unsigned* minor,
unsigned* release)
 
 2389     if(H5get_libversion(major,minor,release) < 0)
 
 2405 NC4_hdf5get_superblock(
struct NC_FILE_INFO* h5, 
int* idp)
 
 2407     NC_HDF5_FILE_INFO_T *hdf5_info;
 
 2412     assert(h5 && h5->format_file_info);
 
 2413     hdf5_info = (NC_HDF5_FILE_INFO_T *)h5->format_file_info;
 
 2415     if((plist = H5Fget_create_plist(hdf5_info->hdfid)) < 0)
 
 2417     if(H5Pget_version(plist, &super, NULL, NULL, NULL) < 0)
 
 2419     if(idp) *idp = (int)super;
 
 2421     if(plist >= 0) H5Pclose(plist);
 
 2425 static int NC4_strict_att_exists(NC_FILE_INFO_T*);
 
 2426 static int NC4_walk(hid_t, 
int*);
 
 2454 NC4_isnetcdf4(
struct NC_FILE_INFO* h5)
 
 2462     exists = NC4_strict_att_exists(h5);
 
 2468     stat = NC4_walk(((NC_HDF5_GRP_INFO_T *)(h5->root_grp->format_grp_info))->hdf_grpid,
 
 2473         isnc4 = (count >= 2);
 
 2488 NC4_strict_att_exists(NC_FILE_INFO_T *h5)
 
 2494     grpid = ((NC_HDF5_GRP_INFO_T *)(h5->root_grp->format_grp_info))->hdf_grpid;
 
 2497     if ((attr_exists = H5Aexists(grpid, NC3_STRICT_ATT_NAME)) < 0)
 
 2499     return (attr_exists?1:0);
 
 2512 NC4_walk(hid_t gid, 
int* countp)
 
 2521     char name[NC_HDF5_MAX_NAME];
 
 2524     err = H5Gget_num_objs(gid, &nobj);
 
 2525     if(err < 0) 
return err;
 
 2527     for(i = 0; i < nobj; i++) {
 
 2529         len = H5Gget_objname_by_idx(gid,(hsize_t)i,name,(
size_t)NC_HDF5_MAX_NAME);
 
 2530         if(len < 0) 
return len;
 
 2532         otype =  H5Gget_objtype_by_idx(gid,(
size_t)i);
 
 2535         grpid = H5Gopen1(gid,name);
 
 2536             NC4_walk(grpid,countp);
 
 2541             if(strcmp(name,
"phony_dim")==0)
 
 2542                 *countp = *countp + 1;
 
 2543             dsid = H5Dopen1(gid,name);
 
 2544             na = H5Aget_num_attrs(dsid);
 
 2545             for(j = 0; j < na; j++) {
 
 2546                 hid_t aid =  H5Aopen_idx(dsid,(
unsigned int)    j);
 
 2548                     const NC_reservedatt* ra;
 
 2549                     ssize_t len = H5Aget_name(aid, NC_HDF5_MAX_NAME, name);
 
 2550                     if(len < 0) 
return len;
 
 2553                     ra = NC_findreserved(name);
 
 2555                         *countp = *countp + 1;