char* test_utf_8() { hid_t file, node, unode, dset; size_t len; char res, *path, *attr, **dset_val; file = H5Fopen(FILE, H5F_ACC_RDONLY, H5P_DEFAULT); mu_assert("H5Fopen() open file...", file >= 0); mu_assert("Valid node path...", AH5_path_valid(file, NODE_PATH)); node = H5Oopen(file, NODE_PATH, H5P_DEFAULT); mu_assert("H5Oopen() open node...", node >= 0); mu_assert("Valid unode path...", AH5_path_valid(node, UNODE_PATH)); unode = H5Oopen(node, UNODE_PATH, H5P_DEFAULT); mu_assert("H5Oopen() open unode...", unode >= 0); H5Oclose(unode); path = (char*) malloc(sizeof(char) * (1 + strlen(NODE_PATH) + 1 + strlen(UNODE_PATH) + 1)); path[0] = '/'; path[1] = '\0'; strcat(path, NODE_PATH); strcat(path, "/"); strcat(path, UNODE_PATH); mu_assert("Valid unode absolute path...", AH5_path_valid(file, path)); unode = H5Oopen(file, path, H5P_DEFAULT); mu_assert("H5Oopen() open unode...", unode >= 0); free(path); len = AH5_read_str_attr_len(unode, ".", "attribut du sous-nœud accentué"); mu_assert("AH5_read_str_attr_len() read utf-8 attr len...", len > 0); attr = (char*) malloc(sizeof(char) * (len + 1)); res = AH5_read_str_attr(unode, ".", "attribut du sous-nœud accentué", &attr); mu_assert("AH5_read_str_attr() status...", res == AH5_TRUE); mu_assert("AH5_read_str_attr() str length...", strlen(attr) == strlen("é è à œ")); mu_assert("AH5_read_str_attr() str value...", strcmp(attr, "é è à œ") == 0); free(attr); mu_assert("Valid dset path...", AH5_path_valid(unode, DSET_PATH)); dset = H5Oopen(unode, DSET_PATH, H5P_DEFAULT); mu_assert("H5Oopen() open dset...", dset >= 0); len = 11; dset_val = (char**) malloc(sizeof(char*)); dset_val[0] = (char*) malloc(sizeof(char) * (len + 1)); res = AH5_read_str_dataset(dset, ".", 1, len, &dset_val); mu_assert("AH5_read_str_dataset() status...", res == AH5_TRUE); mu_assert("AH5_read_str_dataset() str length...", strlen(dset_val[0]) == strlen("é è à œ")); mu_assert("AH5_read_str_dataset() str value...", strcmp(dset_val[0], "é è à œ") == 0); free(dset_val[0]); free(dset_val); H5Oclose(dset); H5Oclose(unode); H5Oclose(node); H5Fclose(file); return MU_FINISHED_WITHOUT_ERRORS; }
/*-------------------------------------------------------------*/ static hid_t findDependentField(pNXVcontext self, hid_t inFieldID,char *dpData) { char *pPtr; hid_t fieldID, groupID; char fname[512], newPath[1024], groupName[1024]; /* get at enclosing group */ memset(groupName,0,sizeof(groupName)); H5Iget_name(inFieldID,groupName,sizeof(groupName)); pPtr = strrchr(groupName,'/'); *pPtr = '\0'; pPtr = NULL; pPtr = strchr(dpData,'/'); if(pPtr != NULL){ if(pPtr == dpData){ /* absolute path */ if(H5LTpath_valid(self->fileID,dpData,1)){ fieldID = H5Oopen(self->fileID,dpData,H5P_DEFAULT); return fieldID; } else { return -1; } } else { /* relative path further along the path */ snprintf(newPath,sizeof(newPath), "%s/%s", groupName, dpData); if(H5LTpath_valid(self->fileID,newPath,1)){ fieldID = H5Oopen(self->fileID,newPath,H5P_DEFAULT); return fieldID; } else { return -1; } } } else { /* path within the group */ groupID = H5Oopen(self->fileID, groupName,H5P_DEFAULT); if(H5LTfind_dataset(groupID,dpData)){ fieldID = H5Dopen(groupID,dpData,H5P_DEFAULT); H5Oclose(groupID); return fieldID; } else { H5Oclose(groupID); return -1; } } return -1; }
/************************************************************ Operator function. Prints the name and type of the object being examined. ************************************************************/ static herr_t op_func_v1(hid_t loc_id, const char *name, const H5L_info_t *info, void *operator_data) { H5O_info_t oinfo; herr_t status = 0; int *pDataSetId = (int*)operator_data; hid_t obj = H5Oopen(loc_id, name, H5P_DEFAULT); if (obj < 0) { return -1; } /* * Get type of the object and return only datasetId * through operator_data. */ status = H5Oget_info(obj, &oinfo); if (status < 0) { H5Oclose(obj); return -1; } if (oinfo.type == H5O_TYPE_DATASET) { *pDataSetId = obj; } else { H5Oclose(obj); } return 0; }
// Write complex attribute <attr_name> given by address <path> char AH5_write_cpx_attr(hid_t loc_id, const char* path, char* attr_name, const AH5_complex_t wdata) { char success = AH5_FALSE; hid_t attr_id = 0, cpx_filetype, cpx_memtype, object_id, space; hsize_t dims[1] = {1}; cpx_filetype = AH5_H5Tcreate_cpx_filetype(); cpx_memtype = AH5_H5Tcreate_cpx_memtype(); space = H5Screate_simple (1, dims, NULL); if (AH5_path_valid(loc_id, path)) { if ((object_id = H5Oopen(loc_id, path, H5P_DEFAULT)) >= 0) { if ((attr_id = H5Acreate(object_id, attr_name, cpx_filetype, space, H5P_DEFAULT, H5P_DEFAULT)) >= 0) { if (H5Awrite(attr_id, cpx_memtype, &wdata) >= 0) { success = AH5_TRUE; } H5Aclose(attr_id); } H5Oclose(object_id); } } H5Sclose(space); H5Tclose(cpx_memtype); H5Tclose(cpx_filetype); return success; }
static hid_t UD_soft_traverse(const char *link_name, hid_t cur_group, const void *udata, size_t udata_size, hid_t lapl_id) { const char *target = (const char *) udata; hid_t ret_value; /* Pass the udata straight through to HDF5. If it's invalid, let HDF5 * return an error. */ ret_value = H5Oopen(cur_group, target, lapl_id); return ret_value; }
herr_t H5Group::printLsInfo(hid_t g_id, const char * name, const H5L_info_t * info, void * op_data) { H5O_info_t oinfo; herr_t err; H5Object * hobj = 0; hid_t obj = 0; OpDataPrintLs & opdata = *(OpDataPrintLs *)op_data; switch (info->type) { case H5L_TYPE_SOFT: hobj = new H5SoftLink(*opdata.parent, name); break; case H5L_TYPE_EXTERNAL: hobj = new H5ExternalLink(*opdata.parent, name); break; case H5L_TYPE_HARD: obj = H5Oopen(g_id, name, H5P_DEFAULT); err = H5Oget_info(obj, &oinfo); H5Oclose(obj); if (err < 0) { return (herr_t) - 1; } switch (oinfo.type) { case H5O_TYPE_GROUP: hobj = new H5Group(*opdata.parent, name); break; case H5O_TYPE_DATASET: hobj = new H5Dataset(*opdata.parent, name); break; case H5O_TYPE_NAMED_DATATYPE: hobj = new H5Type(*opdata.parent, name); break; default: return (herr_t) - 1; } break; default: return (herr_t) - 1; } hobj->printLsInfo(*opdata.os); delete hobj; return (herr_t)0; }
Object::Object( Location const& location , optional<LinkAccessProperties> const& optional_properties ) // {{{ : Contained( location.getFile(), assertSuccess( "opening object", H5Oopen( location.getParentId(), location.getNameAsCStr(), getOptionalPropertiesId(optional_properties) ) ), H5Oclose ) {} // }}}
H5Object & H5File::getRoot() { hid_t obj = H5Oopen(getH5Id(), path.c_str(), H5P_DEFAULT); if (obj < 0) { throw H5Exception(__LINE__, __FILE__, _("Invalid path: %s"), path.c_str()); } try { return H5Object::getObject(*this, obj); } catch (const H5Exception & /*e*/) { H5Oclose(obj); throw; } }
/* * Class: hdf_hdf5lib_H5 * Method: _H5Oopen * Signature: (JLjava/lang/String;J)J */ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Oopen (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jlong access_plist_id) { hid_t status = -1; const char *oName; PIN_JAVA_STRING(name, oName); if (oName != NULL) { status = H5Oopen((hid_t)loc_id, oName, (hid_t)access_plist_id ); UNPIN_JAVA_STRING(name, oName); if (status < 0) h5libraryError(env); } return (jlong)status; } /* end Java_hdf_hdf5lib_H5__1H5Oopen */
/*------------------------------------------------------------------------- * Function: flush_verification * * Purpose: This function tries to open target object in the test file. * It compares the success of the open function to the expected * value, and succeeds if they are equal and fails if they differ. * * Note that full path to the object must be provided as the * obj_pathname argument. * * Return: 0 on Success, 1 on Failure * * Programmer: Mike McGreevy * July 16, 2010 * * Modifications: * *------------------------------------------------------------------------- */ herr_t flush_verification(const char * obj_pathname, const char * expected) { /* Variables */ hid_t oid,fid,status = 0; H5O_info_t oinfo; /* Try to open the testfile and then obj_pathname within the file */ H5E_BEGIN_TRY { fid = H5Fopen(FILENAME, H5F_ACC_SWMR_READ, H5P_DEFAULT); oid = H5Oopen(fid, obj_pathname, H5P_DEFAULT); status = H5Oget_info(oid, &oinfo); } H5E_END_TRY; /* Compare to expected result */ if (strcmp(expected, FLUSHED) == 0) { if ((oid < 0) || (status < 0)) { HDfprintf(stderr, "Error! %s should be on disk, but was NOT!\n", obj_pathname); PROCESS_ERROR; } /* end if */ } else if (strcmp(expected, NOT_FLUSHED) == 0) { if ((oid > 0) || (status > 0)) { HDfprintf(stderr, "Error! %s not expected to be flushed, but it was found on disk!\n", obj_pathname); PROCESS_ERROR; } /* end if */ } else { HDfprintf(stderr, "Error! Bad verification parameters. %s is an invalid expected outcome.\n", expected); PROCESS_ERROR; } /* end if */ /* Cleanup */ H5E_BEGIN_TRY { H5Oclose(oid); H5Fclose(fid); } H5E_END_TRY; return SUCCEED; error: return FAIL; } /* flush_verification */
/* * Class: hdf_hdf5lib_H5 * Method: _H5Oopen * Signature: (JLjava/lang/String;J)J */ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Oopen (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jlong access_plist_id) { const char *objName = NULL; hid_t status = H5I_INVALID_HID; UNUSED(clss); if (NULL == name) H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Oopen: object name is NULL"); PIN_JAVA_STRING(ENVONLY, name, objName, NULL, "H5Oopen: object name not pinned"); if ((status = H5Oopen((hid_t)loc_id, objName, (hid_t)access_plist_id)) < 0) H5_LIBRARY_ERROR(ENVONLY); done: if (objName) UNPIN_JAVA_STRING(ENVONLY, name, objName); return (jlong)status; } /* end Java_hdf_hdf5lib_H5__1H5Oopen */
/* UD_plist_traverse * Open a path passed in through the property list. */ static hid_t UD_plist_traverse(const char *link_name, hid_t cur_group, const void *udata, size_t udata_size, hid_t lapl_id) { char * path; hid_t ret_value = -1; /* If the link property isn't set or can't be found, traversal fails. */ if(H5Pexist(lapl_id, PLIST_LINK_PROP) < 0) goto error; if(H5Pget(lapl_id, PLIST_LINK_PROP, &path) < 0) goto error; /* Open the object by address. If H5Oopen_by_addr fails, ret_value will * be negative to indicate that the traversal function failed. */ ret_value = H5Oopen(cur_group, path, lapl_id); return ret_value; error: return -1; }
/****if* H5Of/h5oopen_c * NAME * h5oopen_c * PURPOSE * Calls H5Oopen * INPUTS * loc_id - File or group identifier * name - Attribute access property list * namelen - Size of name * lapl_id - Link access property list * OUTPUTS * obj_id - Dataset identifier * RETURNS * 0 on success, -1 on failure * AUTHOR * M. Scot Breitenfeld * April 18, 2008 * SOURCE */ int_f nh5oopen_c (hid_t_f *loc_id, _fcd name, size_t_f *namelen, hid_t_f *lapl_id, hid_t_f *obj_id) /******/ { char *c_name = NULL; /* Buffer to hold C string */ int_f ret_value = 0; /* Return value */ /* * Convert FORTRAN name to C name */ if((c_name = HD5f2cstring(name, (size_t)*namelen)) == NULL) HGOTO_DONE(FAIL); /* * Call H5Oopen function. */ if((*obj_id = (hid_t_f)H5Oopen((hid_t)*loc_id, c_name, (hid_t)*lapl_id)) < 0) HGOTO_DONE(FAIL); done: if(c_name) HDfree(c_name); return ret_value; }
int VsFilter::visitLinks(hid_t locId, const char* name, const H5L_info_t *linfo, void* opdata) { VsLog::debugLog() <<"VsFilter::visitLinks() - looking at object " <<name <<std::endl; switch (linfo->type) { case H5L_TYPE_HARD: { H5O_info_t objinfo; /* Stat the object */ if(H5Oget_info_by_name(locId, name, &objinfo, H5P_DEFAULT) < 0) { VsLog::errorLog() <<"VsFilter::visitLinks() - unable to open object with name " <<name <<std::endl; VsLog::errorLog() <<"VsFilter::visitLinks() - this object and all children will be dropped." <<std::endl; return 0; } switch(objinfo.type) { case H5O_TYPE_GROUP: return visitGroup( locId, name, opdata ); break; case H5O_TYPE_DATASET: return visitDataset( locId, name, opdata ); break; default: VsLog::debugLog() << "VsFilter::visitLinks: node '" << name << "' has an unknown type " << objinfo.type << std::endl; break; } } break; //end of case H5L_TYPE_HARD case H5L_TYPE_EXTERNAL: { char *targbuf = (char*) malloc( linfo->u.val_size ); if (H5Lget_val(locId, name, targbuf, linfo->u.val_size, H5P_DEFAULT) < 0) { VsLog::errorLog() <<"VsFilter::visitLinks() - unable to open external link with name " <<targbuf <<std::endl; VsLog::errorLog() <<"VsFilter::visitLinks() - this object and all children will be dropped." <<std::endl; return 0; } const char *filename; const char *targname; if (H5Lunpack_elink_val(targbuf, linfo->u.val_size, 0, &filename, &targname) < 0) { VsLog::errorLog() <<"VsFilter::visitLinks() - unable to open external file with name " <<filename <<std::endl; VsLog::errorLog() <<"VsFilter::visitLinks() - this object and all children will be dropped." <<std::endl; return 0; } VsLog::debugLog() << "VsFilter::visitLinks(): node '" << name << "' is an external link." << std::endl; VsLog::debugLog() << "VsFilter::visitLinks(): node '" << targname << "' is an external target group." << std::endl; free(targbuf); targbuf = NULL; // Get info of the linked object. H5O_info_t objinfo; #ifndef H5_USE_16_API hid_t obj_id = H5Oopen(locId, name, H5P_DEFAULT); #else hid_t obj_id = H5Oopen(locId, name); #endif if (obj_id < 0) { VsLog::errorLog() <<"VsFilter::visitLinks() - unable to get id for external object " <<name <<std::endl; VsLog::errorLog() <<"VsFilter::visitLinks() - this object and all children will be dropped." <<std::endl; return 0; } //Test-open the linked object if (H5Oget_info (obj_id, &objinfo) < 0) { VsLog::errorLog() <<"VsFilter::visitLinks() - unable to open external object " <<name <<std::endl; VsLog::errorLog() <<"VsFilter::visitLinks() - this object and all children will be dropped." <<std::endl; return 0; } //Close the linked object to release hdf5 id H5Oclose( obj_id ); //Finally, decide what to do depending on what type of object this is switch(objinfo.type) { case H5O_TYPE_GROUP: return visitGroup( locId, name, opdata ); break; case H5O_TYPE_DATASET: return visitDataset( locId, name, opdata ); break; default: VsLog::debugLog() << "VsFilter::visitLinks: node '" << name << "' has an unknown type " << objinfo.type << std::endl; break; } } break; //END OF CASE H5L_TYPE_EXTERNAL default: VsLog::debugLog() << "VsFilter::visitLinks: node '" << name << "' has an unknown object type " << linfo->type << std::endl; break; } return 0; }
/*--------------------------------------------------------------*/ static void validateLink(pNXVcontext self, hid_t groupID, xmlChar *name, xmlChar *target) { hid_t objID; herr_t att; char linkTarget[512], dataPath[512]; char nxdlPath[512], curPath[512]; /* set our path for correct error printing */ snprintf(nxdlPath,sizeof(nxdlPath),"%s/%s", self->nxdlPath, (char *)name); NXVsetLog(self,"nxdlPath",nxdlPath); H5Iget_name(groupID,curPath,sizeof(curPath)); snprintf(dataPath,sizeof(dataPath),"%s/%s", curPath, (char *)name); NXVsetLog(self,"dataPath",dataPath); /* log what we are doing */ NXVsetLog(self,"sev","debug"); NXVprintLog(self,"message","Validating link %s at %s", (char *)name, (char *)target); NXVlog(self); /* now we really validate */ if(H5LTpath_valid(groupID,(char *)name, 1)){ /* The positive test means that the link exists and is pointing to a valid HDF5 object. This is alread good. */ objID = H5Oopen(groupID,(char *)name,H5P_DEFAULT); assert(objID >= 0); /* we just tested for existence, didn't we? */ memset(linkTarget,0,sizeof(linkTarget)); att = H5NXget_attribute_string(groupID,(char *)name,"target",linkTarget); if(att < 0){ NXVsetLog(self,"sev","error"); H5Iget_name(objID,dataPath,sizeof(dataPath)); NXVsetLog(self,"dataPath",dataPath); NXVsetLog(self,"message","Link is missing required attribute target"); NXVlog(self); self->errCount++; } else { /* test that the target attribute really points to something real. It could be that the link was done right but the target attribute set sloppily. */ if(!H5LTpath_valid(self->fileID,linkTarget,1)){ NXVsetLog(self,"sev","error"); H5Iget_name(objID,dataPath,sizeof(dataPath)); NXVsetLog(self,"dataPath",dataPath); NXVprintLog(self,"message","Link target %s is invalid", linkTarget); NXVlog(self); self->errCount++; } else { validateLinkTarget(self,target,linkTarget); } } H5Oclose(objID); } else { NXVsetLog(self,"sev","error"); NXVprintLog(self,"message", "Required link %s missing or not pointing to an HDF5 object", (char *)name); NXVlog(self); self->errCount++; } }
/** * Reads an array of double attributes from the HDF5 metadata. * It reads the attributes directly on its binary form directly, * thus avoiding string conversions. * * Important: It allocates the memory for the attributes internally, * so the caller must free the returned array after using it. * @param pszAttrName Name of the attribute to be read. * the attribute name must be the form: * root attribute name * SUBDATASET/subdataset attribute name * @param pdfValues pointer which will store the array of doubles read. * @param nLen it stores the length of the array read. If NULL it doesn't * inform the length of the array. * @return CPLErr CE_None in case of success, CE_Failure in case of failure */ CPLErr HDF5Dataset::HDF5ReadDoubleAttr(const char *pszAttrFullPath, double **pdfValues, int *nLen) { CPLString osAttrFullPath(pszAttrFullPath); // Search for the last "/" in order to get the path to the attribute. const size_t nSlashPos = osAttrFullPath.find_last_of("/"); CPLString osObjName; CPLString osAttrName; // If objects name have been found. if( nSlashPos != CPLString::npos ) { // Split Object name (dataset, group). osObjName = osAttrFullPath.substr(0, nSlashPos); // Split attribute name. osAttrName = osAttrFullPath.substr(nSlashPos + 1); } else { // By default the group is root, and // the attribute is the full path. osObjName = "/"; osAttrName = pszAttrFullPath; } const hid_t hObjAttrID = H5Oopen(hHDF5, osObjName.c_str(), H5P_DEFAULT); CPLErr retVal = CE_Failure; if(hObjAttrID < 0) { CPLError(CE_Failure, CPLE_OpenFailed, "Object %s could not be opened", pszAttrFullPath); retVal = CE_Failure; } else { // Open attribute handler by name, from the object handler opened // earlier. const hid_t hAttrID = H5Aopen_name(hObjAttrID, osAttrName.c_str()); // Check for errors opening the attribute. if( hAttrID < 0 ) { CPLError(CE_Failure, CPLE_OpenFailed, "Attribute %s could not be opened", pszAttrFullPath); retVal = CE_Failure; } else { const hid_t hAttrTypeID = H5Aget_type(hAttrID); const hid_t hAttrNativeType = H5Tget_native_type(hAttrTypeID, H5T_DIR_DEFAULT); const hid_t hAttrSpace = H5Aget_space(hAttrID); hsize_t nSize[64] = {}; const unsigned int nAttrDims = H5Sget_simple_extent_dims(hAttrSpace, nSize, nullptr); if( !H5Tequal(H5T_NATIVE_DOUBLE, hAttrNativeType) ) { CPLError(CE_Failure, CPLE_OpenFailed, "Attribute %s is not of type double", pszAttrFullPath); retVal = CE_Failure; } else { // Get the amount of elements. unsigned int nAttrElmts = 1; for( hsize_t i = 0; i < nAttrDims; i++ ) { // For multidimensional attributes nAttrElmts *= static_cast<unsigned int>(nSize[i]); } if(nLen != nullptr) *nLen = nAttrElmts; *pdfValues = static_cast<double *>( CPLMalloc(nAttrElmts * sizeof(double))); // Read the attribute contents if( H5Aread(hAttrID, hAttrNativeType, *pdfValues) < 0 ) { CPLError(CE_Failure, CPLE_OpenFailed, "Attribute %s could not be opened", pszAttrFullPath); retVal = CE_Failure; } else { retVal = CE_None; } } H5Tclose(hAttrNativeType); H5Tclose(hAttrTypeID); H5Sclose(hAttrSpace); H5Aclose(hAttrID); } H5Oclose(hObjAttrID); } return retVal; }
/*------------------------------------------------------------------------- * Function: refresh_verification * * Purpose: This function opens the specified object, and checks to see * that is does not have any attributes on it. It then sends * a signal to the main process, which will flush the object * (putting an attribute on the object on disk). This function * will then refresh the object, and verify that it has picked * up the new metadata reflective of the added attribute. * * Return: 0 on Success, 1 on Failure * * Programmer: Mike McGreevy * July 16, 2010 * * Modifications: * *------------------------------------------------------------------------- */ herr_t refresh_verification(const char * obj_pathname) { /* Variables */ hid_t oid,fid,status = 0; H5O_info_t flushed_oinfo; H5O_info_t refreshed_oinfo; /* Open Object */ if ((fid = H5Fopen(FILENAME, H5F_ACC_SWMR_READ, H5P_DEFAULT)) < 0) PROCESS_ERROR; if ((oid = H5Oopen(fid, obj_pathname, H5P_DEFAULT)) < 0) PROCESS_ERROR; /* Get Object info */ if ((status = H5Oget_info(oid, &flushed_oinfo)) < 0) PROCESS_ERROR; /* Make sure there are no attributes on the object. This is just a sanity check to ensure we didn't erroneously flush the attribute before starting the verification. */ if (flushed_oinfo.num_attrs != 0) PROCESS_ERROR; /* Send Signal to MAIN PROCESS indicating that it can go ahead and modify the object. */ send_signal(SIGNAL_BETWEEN_PROCESSES_1, NULL, NULL); /* Wait for Signal from MAIN PROCESS indicating that it's modified the object and we can run verification now. */ if (wait_for_signal(SIGNAL_BETWEEN_PROCESSES_2) < 0) PROCESS_ERROR; /* Get object info again. This will NOT reflect what's on disk, only what's in the cache. Thus, all values will be unchanged from above, despite newer information being on disk. */ if ((status = H5Oget_info(oid, &refreshed_oinfo)) < 0) PROCESS_ERROR; /* Verify that before doing a refresh, getting the object info returns stale information. (i.e., unchanged from above, despite new info on disk). */ if (flushed_oinfo.addr != refreshed_oinfo.addr) PROCESS_ERROR; if (flushed_oinfo.type != refreshed_oinfo.type) PROCESS_ERROR; if (flushed_oinfo.hdr.version != refreshed_oinfo.hdr.version) PROCESS_ERROR; if (flushed_oinfo.hdr.flags != refreshed_oinfo.hdr.flags) PROCESS_ERROR; if (flushed_oinfo.num_attrs != refreshed_oinfo.num_attrs) PROCESS_ERROR; if (flushed_oinfo.hdr.nmesgs != refreshed_oinfo.hdr.nmesgs) PROCESS_ERROR; if (flushed_oinfo.hdr.nchunks != refreshed_oinfo.hdr.nchunks) PROCESS_ERROR; if (flushed_oinfo.hdr.space.total != refreshed_oinfo.hdr.space.total) PROCESS_ERROR; /* Refresh object */ /* The H5*refresh function called depends on which object we are trying * to refresh. (MIKE: add desired refresh call as parameter so adding new * test cases is easy). */ if ((strcmp(obj_pathname, D1) == 0) || (strcmp(obj_pathname, D2) == 0)) { if (H5Drefresh(oid) < 0) PROCESS_ERROR; } /* end if */ else if ((strcmp(obj_pathname, G1) == 0) || (strcmp(obj_pathname, G2) == 0)) { if (H5Grefresh(oid) < 0) PROCESS_ERROR; } /* end if */ else if ((strcmp(obj_pathname, T1) == 0) || (strcmp(obj_pathname, T2) == 0)) { if (H5Trefresh(oid) < 0) PROCESS_ERROR; } /* end if */ else if ((strcmp(obj_pathname, D3) == 0) || (strcmp(obj_pathname, G3) == 0) || (strcmp(obj_pathname, T3) == 0)) { if (H5Orefresh(oid) < 0) PROCESS_ERROR; } /* end if */ else { HDfprintf(stdout, "Error. %s is an unrecognized object.\n", obj_pathname); PROCESS_ERROR; } /* end else */ /* Get object info. This should now accurately reflect the refreshed object on disk. */ if ((status = H5Oget_info(oid, &refreshed_oinfo)) < 0) PROCESS_ERROR; /* Confirm following attributes are the same: */ if (flushed_oinfo.addr != refreshed_oinfo.addr) PROCESS_ERROR; if (flushed_oinfo.type != refreshed_oinfo.type) PROCESS_ERROR; if (flushed_oinfo.hdr.version != refreshed_oinfo.hdr.version) PROCESS_ERROR; if (flushed_oinfo.hdr.flags != refreshed_oinfo.hdr.flags) PROCESS_ERROR; /* Confirm following attributes are different */ if (flushed_oinfo.num_attrs == refreshed_oinfo.num_attrs) PROCESS_ERROR; if (flushed_oinfo.hdr.nmesgs == refreshed_oinfo.hdr.nmesgs) PROCESS_ERROR; if (flushed_oinfo.hdr.nchunks == refreshed_oinfo.hdr.nchunks) PROCESS_ERROR; if (flushed_oinfo.hdr.space.total == refreshed_oinfo.hdr.space.total) PROCESS_ERROR; /* Close objects */ if (H5Oclose(oid) < 0) PROCESS_ERROR; if (H5Fclose(fid) < 0) PROCESS_ERROR; /* Return */ return SUCCEED; error: return FAIL; } /* refresh_verification */
/* "Windows to Unix" traversal function for external links * * Translates a filename stored in Unix format to Windows format by replacing * forward slashes with backslashes. * Makes no attempt to handle Windows drive names (e.g., "C:\"), spaces within * file names, quotes, etc. These are left as an exercise for the user. :) * Note that this may not be necessary on your system; many Windows systems can * understand Unix paths. */ static hid_t elink_unix2win_trav(const char *link_name, hid_t cur_group, const void *udata, size_t udata_size, hid_t lapl_id) { hid_t fid; const char *file_name; const char *obj_name; char *new_fname = NULL; /* Buffer allocated to hold Unix file path */ ssize_t prefix_len; /* External link prefix length */ size_t fname_len; size_t start_pos; /* Initial position in new_fname buffer */ size_t x; /* Counter variable */ hid_t ret_value = -1; printf("Converting Unix path to Windows path.\n"); if(H5Lunpack_elink_val(udata, udata_size, NULL, &file_name, &obj_name) < 0) goto error; fname_len = strlen(file_name); /* See if the external link prefix property is set */ if((prefix_len = H5Pget_elink_prefix(lapl_id, NULL, 0)) < 0) goto error; /* If so, prepend it to the filename. We assume that the prefix * is in the correct format for the current file system. */ if(prefix_len > 0) { /* Allocate a buffer to hold the filename plus prefix */ new_fname = malloc(prefix_len + fname_len + 1); /* Copy the prefix into the buffer */ if(H5Pget_elink_prefix(lapl_id, new_fname, (size_t)(prefix_len + 1)) < 0) goto error; start_pos = prefix_len; } else { /* Allocate a buffer to hold just the filename */ new_fname = malloc(fname_len + 1); start_pos = 0; } /* We should now copy file_name into new_fname starting at position pos. * We'll convert '/' characters into '\' characters as we go. */ for(x=0; file_name[x] != '\0'; x++) { if(file_name[x] == '/') new_fname[x + start_pos] = '\\'; else new_fname[x + start_pos] = file_name[x]; } new_fname[x + start_pos] = '\0'; /* Now open the file and object within it */ if((fid = H5Fopen(new_fname, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) goto error; ret_value = H5Oopen(fid, obj_name, lapl_id); /* If this fails, our return value will be negative. */ if(H5Fclose(fid) < 0) goto error; /* Free file name if it's been allocated */ if(new_fname) free(new_fname); return ret_value; error: /* Free file name if it's been allocated */ if(new_fname) free(new_fname); return -1; }
hid_t H5Dataset::create(H5Object & loc, const std::string & name, const hid_t type, const hid_t targettype, const hid_t srcspace, const hid_t targetspace, void * data, const bool chunked) { herr_t err; hid_t dataset; if (H5Lexists(loc.getH5Id(), name.c_str(), H5P_DEFAULT) > 0) { dataset = H5Oopen(loc.getH5Id(), name.c_str(), H5P_DEFAULT); if (dataset < 0) { throw H5Exception(__LINE__, __FILE__, _("Cannot open the dataset: %s"), name.c_str()); } if (targetspace > 0) { hid_t space = H5Dget_space(dataset); if (space < 0) { throw H5Exception(__LINE__, __FILE__, _("Cannot get the dataspace associated with dataset named %s."), name.c_str()); } hsize_t * dims = 0; hsize_t * ddims = 0; hsize_t * maxdims = 0; hsize_t * dmaxdims = 0; try { herr_t err; int ndims = H5Sget_simple_extent_ndims(space); if (ndims < 0) { throw H5Exception(__LINE__, __FILE__, _("Invalid source space")); } int dndims = H5Sget_simple_extent_ndims(targetspace); if (dndims < 0) { throw H5Exception(__LINE__, __FILE__, _("Invalid target space")); } hsize_t * dims = new hsize_t[ndims]; hsize_t * ddims = new hsize_t[dndims]; hsize_t * maxdims = new hsize_t[ndims]; hsize_t * dmaxdims = new hsize_t[dndims]; H5Sget_simple_extent_dims(space, dims, maxdims); H5Sget_simple_extent_dims(targetspace, ddims, dmaxdims); H5Sclose(space); if (ndims != dndims) { throw H5Exception(__LINE__, __FILE__, _("Wrong dimensions.")); } else { for (int i = 0; i < ndims; i++) { if (maxdims[i] != dmaxdims[i]) { throw H5Exception(__LINE__, __FILE__, _("Cannot modify maximum dimensions.")); } if (ddims[i] > dims[i]) { err = H5Dset_extent(dataset, ddims); if (err < 0) { throw H5Exception(__LINE__, __FILE__, _("Cannot modify dimension %d."), i); } break; } } } delete[] dims; delete[] ddims; delete[] maxdims; delete[] dmaxdims; } catch (const H5Exception & /*e*/) { delete[] dims; delete[] ddims; delete[] maxdims; delete[] dmaxdims; throw; } } } else { if (chunked) { herr_t err; int ndims = H5Sget_simple_extent_ndims(targetspace); if (ndims < 0) { throw H5Exception(__LINE__, __FILE__, _("Invalid target space")); } hsize_t * dims = new hsize_t[ndims]; H5Sget_simple_extent_dims(targetspace, dims, 0); hid_t dcpl = H5Pcreate(H5P_DATASET_CREATE); H5Pset_layout(dcpl, H5D_CHUNKED); err = H5Pset_chunk(dcpl, ndims, dims); delete[] dims; if (err < 0) { H5Pclose(dcpl); throw H5Exception(__LINE__, __FILE__, _("Cannot set the chunk dimensions: %s"), name.c_str()); } dataset = H5Dcreate(loc.getH5Id(), name.c_str(), targettype, targetspace == -1 ? srcspace : targetspace, H5P_DEFAULT, dcpl, H5P_DEFAULT); H5Pclose(dcpl); } else { dataset = H5Dcreate(loc.getH5Id(), name.c_str(), targettype, targetspace == -1 ? srcspace : targetspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); } if (dataset < 0) { throw H5Exception(__LINE__, __FILE__, _("Cannot create the dataset: %s"), name.c_str()); } } err = H5Dwrite(dataset, type, srcspace, targetspace == -1 ? H5S_ALL : targetspace, H5P_DEFAULT, data); if (err < 0) { throw H5Exception(__LINE__, __FILE__, _("Cannot write data in the dataset.")); } return dataset; }