/* * Class: hdf_hdf5lib_H5 * Method: H5Aget_info * Signature: (J)Lhdf/hdf5lib/structs/H5A_info_t; */ JNIEXPORT jobject JNICALL Java_hdf_hdf5lib_H5_H5Aget_1info (JNIEnv *env, jclass clss, jlong attr_id) { herr_t status = -1; H5A_info_t ainfo; jvalue args[4]; jobject ret_obj = NULL; status = H5Aget_info((hid_t)attr_id, &ainfo); if (status < 0) { h5libraryError(env); } /* end if */ else { args[0].z = ainfo.corder_valid; args[1].j = ainfo.corder; args[2].i = ainfo.cset; args[3].j = (jlong)ainfo.data_size; CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5A_info_t", "(ZJIJ)V", args); } /* end else */ return ret_obj; } /* end Java_hdf_hdf5lib_H5_H5Aget_1info */
void pyne::Material::_load_comp_protocol1(hid_t db, std::string datapath, int row) { std::string nucpath; hid_t data_set = H5Dopen2(db, datapath.c_str(), H5P_DEFAULT); hsize_t data_offset[1] = {row}; if (row < 0) { // Handle negative row indices hid_t data_space = H5Dget_space(data_set); hsize_t data_dims[1]; H5Sget_simple_extent_dims(data_space, data_dims, NULL); data_offset[0] += data_dims[0]; }; // Grab the nucpath hid_t nuc_attr = H5Aopen(data_set, "nucpath", H5P_DEFAULT); H5A_info_t nuc_info; H5Aget_info(nuc_attr, &nuc_info); hsize_t nuc_attr_len = nuc_info.data_size; hid_t str_attr = H5Tcopy(H5T_C_S1); H5Tset_size(str_attr, nuc_attr_len); char * nucpathbuf = new char [nuc_attr_len]; H5Aread(nuc_attr, str_attr, nucpathbuf); nucpath = std::string(nucpathbuf, nuc_attr_len); delete[] nucpathbuf; // Grab the nuclides std::vector<int> nuclides = h5wrap::h5_array_to_cpp_vector_1d<int>(db, nucpath, H5T_NATIVE_INT); int nuc_size = nuclides.size(); hsize_t nuc_dims[1] = {nuc_size}; // Get the data hyperslab hid_t data_hyperslab = H5Dget_space(data_set); hsize_t data_count[1] = {1}; H5Sselect_hyperslab(data_hyperslab, H5S_SELECT_SET, data_offset, NULL, data_count, NULL); // Get memory space for writing hid_t mem_space = H5Screate_simple(1, data_count, NULL); // Get material type size_t material_struct_size = sizeof(pyne::material_struct) + sizeof(double)*nuc_size; hid_t desc = H5Tcreate(H5T_COMPOUND, material_struct_size); hid_t comp_values_array_type = H5Tarray_create2(H5T_NATIVE_DOUBLE, 1, nuc_dims); // make the data table type H5Tinsert(desc, "mass", HOFFSET(pyne::material_struct, mass), H5T_NATIVE_DOUBLE); H5Tinsert(desc, "density", HOFFSET(pyne::material_struct, density), H5T_NATIVE_DOUBLE); H5Tinsert(desc, "atoms_per_molecule", HOFFSET(pyne::material_struct, atoms_per_mol), H5T_NATIVE_DOUBLE); H5Tinsert(desc, "comp", HOFFSET(pyne::material_struct, comp), comp_values_array_type); // make the data array, have to over-allocate material_struct * mat_data = new material_struct [material_struct_size]; // Finally, get data and put in on this instance H5Dread(data_set, desc, mem_space, data_hyperslab, H5P_DEFAULT, mat_data); mass = (*mat_data).mass; density = (*mat_data).density; atoms_per_molecule = (*mat_data).atoms_per_mol; for (int i = 0; i < nuc_size; i++) comp[nuclides[i]] = (double) (*mat_data).comp[i]; delete[] mat_data; H5Tclose(str_attr); // // Get metadata from associated dataset, if available // std::string attrpath = datapath + "_metadata"; bool attrpath_exists = h5wrap::path_exists(db, attrpath); if (!attrpath_exists) return; hid_t metadatapace, attrtype, metadataet, metadatalab, attrmemspace; int attrrank; hvl_t attrdata [1]; attrtype = H5Tvlen_create(H5T_NATIVE_CHAR); // Get the metadata from the file metadataet = H5Dopen2(db, attrpath.c_str(), H5P_DEFAULT); metadatalab = H5Dget_space(metadataet); H5Sselect_hyperslab(metadatalab, H5S_SELECT_SET, data_offset, NULL, data_count, NULL); attrmemspace = H5Screate_simple(1, data_count, NULL); H5Dread(metadataet, attrtype, attrmemspace, metadatalab, H5P_DEFAULT, attrdata); // convert to in-memory JSON Json::Reader reader; reader.parse((char *) attrdata[0].p, (char *) attrdata[0].p+attrdata[0].len, metadata, false); // close attr data objects H5Fflush(db, H5F_SCOPE_GLOBAL); H5Dclose(metadataet); H5Sclose(metadatapace); H5Tclose(attrtype); // Close out the HDF5 file H5Fclose(db); };