/*------------------------------------------------------------------------- * Function: H5T__print_stats * * Purpose: Print statistics about a conversion path. Statistics are * printed only if all the following conditions are true: * * 1. The library was compiled with H5T_DEBUG defined. * 2. Data type debugging is turned on at run time. * 3. The path was called at least one time. * * The optional NPRINT argument keeps track of the number of * conversions paths for which statistics have been shown. If * its value is zero then table headers are printed before the * first line of output. * * Return: Success: non-negative * * Failure: negative * * Programmer: Robb Matzke * Monday, December 14, 1998 * * Modifications: * *------------------------------------------------------------------------- */ herr_t H5T__print_stats(H5T_path_t H5_ATTR_UNUSED * path, int H5_ATTR_UNUSED * nprint/*in,out*/) { #ifdef H5T_DEBUG hsize_t nbytes; char bandwidth[32]; #endif FUNC_ENTER_PACKAGE_NOERR #ifdef H5T_DEBUG if(H5DEBUG(T) && path->stats.ncalls > 0) { if(nprint && 0 == (*nprint)++) { HDfprintf(H5DEBUG(T), "H5T: type conversion statistics:\n"); HDfprintf(H5DEBUG(T), " %-16s %10s %10s %8s %8s %8s %10s\n", "Conversion", "Elmts", "Calls", "User", "System", "Elapsed", "Bandwidth"); HDfprintf(H5DEBUG(T), " %-16s %10s %10s %8s %8s %8s %10s\n", "----------", "-----", "-----", "----", "------", "-------", "---------"); } if(path->src && path->dst) nbytes = MAX(H5T_get_size(path->src), H5T_get_size(path->dst)); else if(path->src) nbytes = H5T_get_size(path->src); else if(path->dst) nbytes = H5T_get_size(path->dst); else nbytes = 0; nbytes *= path->stats.nelmts; H5_bandwidth(bandwidth, (double)nbytes, path->stats.timer.etime); HDfprintf(H5DEBUG(T), " %-16s %10Hd %10d %8.2f %8.2f %8.2f %10s\n", path->name, path->stats.nelmts, path->stats.ncalls, path->stats.timer.utime, path->stats.timer.stime, path->stats.timer.etime, bandwidth); } #endif FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5T__print_stats() */
/*------------------------------------------------------------------------- * Function: H5O_layout_copy_file * * Purpose: Copies a message from _MESG to _DEST in file * * Return: Success: Ptr to _DEST * * Failure: NULL * * Programmer: Peter Cao * July 23, 2005 * *------------------------------------------------------------------------- */ static void * H5O_layout_copy_file(H5F_t *file_src, void *mesg_src, H5F_t *file_dst, hbool_t UNUSED *recompute_size, H5O_copy_t *cpy_info, void *_udata, hid_t dxpl_id) { H5D_copy_file_ud_t *udata = (H5D_copy_file_ud_t *)_udata; /* Dataset copying user data */ H5O_layout_t *layout_src = (H5O_layout_t *) mesg_src; H5O_layout_t *layout_dst = NULL; hbool_t copied = FALSE; /* Whether the data was copied */ void *ret_value; /* Return value */ FUNC_ENTER_NOAPI_NOINIT(H5O_layout_copy_file) /* check args */ HDassert(file_src); HDassert(layout_src); HDassert(file_dst); /* Allocate space for the destination layout */ if(NULL == (layout_dst = H5FL_MALLOC(H5O_layout_t))) HGOTO_ERROR(H5E_OHDR, H5E_CANTALLOC, NULL, "memory allocation failed") /* Copy the "top level" information */ *layout_dst = *layout_src; /* Copy the layout type specific information */ switch(layout_src->type) { case H5D_COMPACT: if(layout_src->storage.u.compact.buf) { /* copy compact raw data */ if(H5D_compact_copy(file_src, &layout_src->storage.u.compact, file_dst, &layout_dst->storage.u.compact, udata->src_dtype, cpy_info, dxpl_id) < 0) HGOTO_ERROR(H5E_OHDR, H5E_CANTCOPY, NULL, "unable to copy chunked storage") copied = TRUE; } /* end if */ break; case H5D_CONTIGUOUS: /* Compute the size of the contiguous storage for versions of the * layout message less than version 3 because versions 1 & 2 would * truncate the dimension sizes to 32-bits of information. - QAK 5/26/04 */ if(layout_src->version < H5O_LAYOUT_VERSION_3) layout_dst->storage.u.contig.size = H5S_extent_nelem(udata->src_space_extent) * H5T_get_size(udata->src_dtype); if(H5D_contig_is_space_alloc(&layout_src->storage)) { /* copy contiguous raw data */ if(H5D_contig_copy(file_src, &layout_src->storage.u.contig, file_dst, &layout_dst->storage.u.contig, udata->src_dtype, cpy_info, dxpl_id) < 0) HGOTO_ERROR(H5E_OHDR, H5E_CANTCOPY, NULL, "unable to copy contiguous storage") copied = TRUE; } /* end if */ break; case H5D_CHUNKED: if(H5D_chunk_is_space_alloc(&layout_src->storage)) { /* Create chunked layout */ if(H5D_chunk_copy(file_src, &layout_src->storage.u.chunk, &layout_src->u.chunk, file_dst, &layout_dst->storage.u.chunk, udata->src_space_extent, udata->src_dtype, udata->common.src_pline, cpy_info, dxpl_id) < 0) HGOTO_ERROR(H5E_OHDR, H5E_CANTCOPY, NULL, "unable to copy chunked storage") copied = TRUE; } /* end if */ break; default: HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, NULL, "Invalid layout class") } /* end switch */ /* Check if copy routine was invoked (which frees the source datatype) */ if(copied) udata->src_dtype = NULL; /* Set return value */ ret_value = layout_dst; done: if(!ret_value) if(layout_dst) layout_dst = H5FL_FREE(H5O_layout_t, layout_dst); FUNC_LEAVE_NOAPI(ret_value) } /* end H5O_layout_copy_file() */
hid_t dst_id, src_id; /* Source & destination datatypes for type conversion */ uint8_t *bkg_buf = NULL; /* Background conversion buffer */ size_t bkg_size; /* Size of background buffer */ /* Wrap copies of types to convert */ dst_id = H5I_register(H5I_DATATYPE, H5T_copy(dest->type, H5T_COPY_TRANSIENT)); if(dst_id < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to copy/register datatype") src_id = H5I_register(H5I_DATATYPE, H5T_copy(mesg->type, H5T_COPY_ALL)); if(src_id < 0) { H5I_dec_ref(dst_id); HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to copy/register datatype") } /* end if */ /* Allocate a background buffer */ bkg_size = MAX(H5T_get_size(dest->type), H5T_get_size(mesg->type)); if(H5T_path_bkg(tpath) && NULL == (bkg_buf = H5FL_BLK_CALLOC(type_conv, bkg_size))) { H5I_dec_ref(src_id); H5I_dec_ref(dst_id); HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") } /* end if */ /* Convert fill value */ if(H5T_convert(tpath, src_id, dst_id, (size_t)1, (size_t)0, (size_t)0, dest->buf, bkg_buf, H5AC_ind_dxpl_id) < 0) { H5I_dec_ref(src_id); H5I_dec_ref(dst_id); if(bkg_buf) H5FL_BLK_FREE(type_conv, bkg_buf); HGOTO_ERROR(H5E_DATASET, H5E_CANTCONVERT, FAIL, "datatype conversion failed") } /* end if */
/*-------------------------------------------------------------------------- NAME H5O_attr_decode PURPOSE Decode a attribute message and return a pointer to a memory struct with the decoded information USAGE void *H5O_attr_decode(f, raw_size, p) H5F_t *f; IN: pointer to the HDF5 file struct size_t raw_size; IN: size of the raw information buffer const uint8_t *p; IN: the raw information buffer RETURNS Pointer to the new message in native order on success, NULL on failure DESCRIPTION This function decodes the "raw" disk form of a attribute message into a struct in memory native format. The struct is allocated within this function using malloc() and is returned to the caller. --------------------------------------------------------------------------*/ static void * H5O_attr_decode(H5F_t *f, hid_t dxpl_id, const uint8_t *p) { H5A_t *attr = NULL; H5S_extent_t *extent; /*extent dimensionality information */ size_t name_len; /*attribute name length */ int version; /*message version number*/ unsigned flags = 0; /* Attribute flags */ H5A_t *ret_value; /* Return value */ FUNC_ENTER_NOAPI_NOINIT(H5O_attr_decode); /* check args */ HDassert(f); HDassert(p); if(NULL == (attr = H5FL_CALLOC(H5A_t))) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed"); /* Version number */ version = *p++; if (version!=H5O_ATTR_VERSION && version!=H5O_ATTR_VERSION_NEW) HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, NULL, "bad version number for attribute message"); /* Get the flags byte if we have a later version of the attribute */ if(version>H5O_ATTR_VERSION) flags = *p++; else p++; /* Byte is unused when version<2 */ /* * Decode the sizes of the parts of the attribute. The sizes stored in * the file are exact but the parts are aligned on 8-byte boundaries. */ UINT16DECODE(p, name_len); /*including null*/ UINT16DECODE(p, attr->dt_size); UINT16DECODE(p, attr->ds_size); /* Decode and store the name */ if (NULL==(attr->name=H5MM_strdup((const char *)p))) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed"); if(version < H5O_ATTR_VERSION_NEW) p += H5O_ALIGN(name_len); /* advance the memory pointer */ else p += name_len; /* advance the memory pointer */ /* decode the attribute datatype */ if (flags & H5O_ATTR_FLAG_TYPE_SHARED) { H5O_shared_t *shared; /* Shared information */ /* Get the shared information */ if (NULL == (shared = (H5O_MSG_SHARED->decode) (f, dxpl_id, p))) HGOTO_ERROR(H5E_OHDR, H5E_CANTDECODE, NULL, "unable to decode shared message"); /* Get the actual datatype information */ if((attr->dt= H5O_shared_read(f, dxpl_id, shared, H5O_MSG_DTYPE, NULL))==NULL) HGOTO_ERROR(H5E_ATTR, H5E_CANTDECODE, NULL, "can't decode attribute datatype"); /* Free the shared information */ H5O_free_real(H5O_MSG_SHARED, shared); } /* end if */ else { if((attr->dt=(H5O_MSG_DTYPE->decode)(f,dxpl_id,p))==NULL) HGOTO_ERROR(H5E_ATTR, H5E_CANTDECODE, NULL, "can't decode attribute datatype"); } /* end else */ if(version < H5O_ATTR_VERSION_NEW) p += H5O_ALIGN(attr->dt_size); else p += attr->dt_size; /* decode the attribute dataspace */ if (NULL==(attr->ds = H5FL_CALLOC(H5S_t))) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed"); if((extent=(H5O_MSG_SDSPACE->decode)(f,dxpl_id,p))==NULL) HGOTO_ERROR(H5E_ATTR, H5E_CANTDECODE, NULL, "can't decode attribute dataspace"); /* Copy the extent information */ HDmemcpy(&(attr->ds->extent),extent, sizeof(H5S_extent_t)); /* Release temporary extent information */ H5FL_FREE(H5S_extent_t,extent); /* Default to entire dataspace being selected */ if(H5S_select_all(attr->ds, 0) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTSET, NULL, "unable to set all selection") if(version < H5O_ATTR_VERSION_NEW) p += H5O_ALIGN(attr->ds_size); else p += attr->ds_size; /* Compute the size of the data */ H5_ASSIGN_OVERFLOW(attr->data_size,H5S_GET_EXTENT_NPOINTS(attr->ds)*H5T_get_size(attr->dt),hsize_t,size_t); /* Go get the data */ if(attr->data_size) { if (NULL==(attr->data = H5FL_BLK_MALLOC(attr_buf, attr->data_size))) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed"); HDmemcpy(attr->data,p,attr->data_size); } /* Indicate that the fill values aren't to be written out */ attr->initialized=1; /* Set return value */ ret_value = attr; done: if(!ret_value) if(attr) { /* Free dynamicly allocated items */ if(H5A_free(attr) < 0) HDONE_ERROR(H5E_ATTR, H5E_CANTRELEASE, NULL, "can't release attribute info") H5FL_FREE(H5A_t, attr); } /* end if */ FUNC_LEAVE_NOAPI(ret_value); }
H5T_path_t *tpath; /* Datatype conversion path */ uint8_t *bkg_buf = NULL; /* Background conversion buffer */ H5T_t *mem_type; /* Pointer to memory datatype */ size_t mem_type_size, file_type_size; /* Size of datatype in memory and on disk */ hid_t mem_tid; /* Memory version of disk datatype */ /* Create temporary datatype for conversion operation */ if(NULL == (mem_type = H5T_copy(dset->shared->type, H5T_COPY_REOPEN))) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, FAIL, "unable to copy file datatype") if((mem_tid = H5I_register(H5I_DATATYPE, mem_type)) < 0) { H5T_close(mem_type); HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register memory datatype") } /* end if */ /* Retrieve sizes of memory & file datatypes */ mem_type_size = H5T_get_size(mem_type); HDassert(mem_type_size > 0); file_type_size = H5T_get_size(dset->shared->type); HDassert(file_type_size == dset->shared->fill.size); /* Get the datatype conversion path for this operation */ if(NULL == (tpath = H5T_path_find(dset->shared->type, mem_type, NULL, NULL, dxpl_id))) { H5I_dec_ref(mem_tid); HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to convert between src and dst datatypes") } /* end if */ /* Allocate a background buffer, if necessary */ if(H5T_path_bkg(tpath) && NULL == (bkg_buf = H5FL_BLK_CALLOC(type_conv, (npoints * MAX(mem_type_size, file_type_size))))) { H5I_dec_ref(mem_tid); HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") } /* end if */