int_f nh5sset_extent_simple_c ( hid_t_f *space_id , int_f *rank, hsize_t_f *current_size, hsize_t_f *maximum_size) { int ret_value = -1; hid_t c_space_id; int c_rank; hsize_t *c_current_size; hsize_t *c_maximum_size; herr_t status; int i; c_current_size = malloc(sizeof(hsize_t)*(*rank)); if (!c_current_size) return ret_value; c_maximum_size = malloc(sizeof(hsize_t)*(*rank)); if (!c_maximum_size) return ret_value; /* * Reverse dimensions due to C-FORTRAN storage order. */ for (i=0; i < *rank; i++) { c_current_size[i] = (hsize_t)current_size[*rank - i - 1]; c_maximum_size[i] = (hsize_t)maximum_size[*rank - i - 1]; } c_space_id = *space_id; c_rank = *rank; status = H5Sset_extent_simple(c_space_id, c_rank, c_current_size, c_maximum_size); if ( status >= 0 ) ret_value = 0; HDfree(c_current_size); HDfree(c_maximum_size); return ret_value; }
void DCDataSet::append(size_t count, size_t offset, size_t stride, const void* data) throw (DCException) { log_msg(2, "DCDataSet::append"); if (!opened) throw DCException(getExceptionString("append: Dataset has not been opened/created.")); log_msg(3, "logical_size = %s", getLogicalSize().toString().c_str()); Dimensions target_offset(getLogicalSize()); // extend size (dataspace) of existing dataset with count elements getLogicalSize()[0] += count; hsize_t * max_dims = new hsize_t[ndims]; for (size_t i = 0; i < ndims; ++i) max_dims[i] = H5F_UNLIMITED; if (H5Sset_extent_simple(dataspace, 1, getLogicalSize().getPointer(), max_dims) < 0) throw DCException(getExceptionString("append: Failed to set new extent")); delete[] max_dims; max_dims = NULL; log_msg(3, "logical_size = %s", getLogicalSize().toString().c_str()); if (H5Dset_extent(dataset, getLogicalSize().getPointer()) < 0) throw DCException(getExceptionString("append: Failed to extend dataset")); // select the region in the target DataSpace to write to Dimensions dim_data(count, 1, 1); if (H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, target_offset.getPointer(), NULL, dim_data.getPointer(), NULL) < 0 || H5Sselect_valid(dataspace) < 0) throw DCException(getExceptionString("append: Invalid target hyperslap selection")); // append data to the dataset. // select the region in the source DataSpace to read from Dimensions dim_src(offset + count * stride, 1, 1); hid_t dsp_src = H5Screate_simple(1, dim_src.getPointer(), NULL); if (dsp_src < 0) throw DCException(getExceptionString("append: Failed to create src dataspace while appending")); if (H5Sselect_hyperslab(dsp_src, H5S_SELECT_SET, Dimensions(offset, 0, 0).getPointer(), Dimensions(stride, 1, 1).getPointer(), dim_data.getPointer(), NULL) < 0 || H5Sselect_valid(dsp_src) < 0) throw DCException(getExceptionString("append: Invalid source hyperslap selection")); if (!data || (count == 0)) { H5Sselect_none(dataspace); data = NULL; } if (H5Dwrite(dataset, this->datatype, dsp_src, dataspace, dsetWriteProperties, data) < 0) throw DCException(getExceptionString("append: Failed to append dataset")); H5Sclose(dsp_src); }
hid_t _write_grid(hid_t loc_id, std::string attr_name, double *attr_array, const hsize_t size) { herr_t status; hid_t attr_id; DataspaceCreate x_grid_space(H5S_SCALAR); status = H5Sset_extent_simple(x_grid_space.dataspace_id, 1, &size, NULL); attr_id = H5Acreate(loc_id, attr_name.c_str(), H5T_NATIVE_DOUBLE, x_grid_space.dataspace_id, H5P_DEFAULT, H5P_DEFAULT); status = H5Awrite(attr_id, H5T_NATIVE_DOUBLE, attr_array); H5Aclose(attr_id); return status; }
void writeInt32Attribute(hid_t element, const char *attr_name, hsize_t dims, int *attr_value) { herr_t hdfstatus = -1; hid_t hdfdatatype = -1; hid_t hdfattr = -1; hid_t hdfattrdataspace = -1; hdfattrdataspace = H5Screate(H5S_SCALAR); hdfdatatype = H5Tcopy(H5T_NATIVE_INT32); if (dims == 1) { } else { hdfattrdataspace = H5Screate(H5S_SIMPLE); H5Sset_extent_simple(hdfattrdataspace, 1, &dims, NULL); } hdfattr = H5Acreate2(element, attr_name, hdfdatatype, hdfattrdataspace, H5P_DEFAULT, H5P_DEFAULT); hdfstatus = H5Awrite(hdfattr, hdfdatatype, attr_value); H5Aclose (hdfattr); H5Sclose(hdfattrdataspace); return; }
void write_header_attributes_in_hdf5(hid_t handle) { hsize_t adim[1] = { 6 }; hid_t hdf5_dataspace, hdf5_attribute; hdf5_dataspace = H5Screate(H5S_SIMPLE); H5Sset_extent_simple(hdf5_dataspace, 1, adim, NULL); hdf5_attribute = H5Acreate(handle, "NumPart_ThisFile", H5T_NATIVE_INT, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_UINT, header.npart); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SIMPLE); H5Sset_extent_simple(hdf5_dataspace, 1, adim, NULL); hdf5_attribute = H5Acreate(handle, "NumPart_Total", H5T_NATIVE_UINT, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_UINT, header.npartTotal); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SIMPLE); H5Sset_extent_simple(hdf5_dataspace, 1, adim, NULL); hdf5_attribute = H5Acreate(handle, "NumPart_Total_HW", H5T_NATIVE_UINT, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_UINT, header.npartTotalHighWord); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SIMPLE); H5Sset_extent_simple(hdf5_dataspace, 1, adim, NULL); hdf5_attribute = H5Acreate(handle, "MassTable", H5T_NATIVE_DOUBLE, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_DOUBLE, header.mass); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SCALAR); hdf5_attribute = H5Acreate(handle, "Time", H5T_NATIVE_DOUBLE, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_DOUBLE, &header.time); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SCALAR); hdf5_attribute = H5Acreate(handle, "Redshift", H5T_NATIVE_DOUBLE, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_DOUBLE, &header.redshift); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SCALAR); hdf5_attribute = H5Acreate(handle, "BoxSize", H5T_NATIVE_DOUBLE, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_DOUBLE, &header.BoxSize); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SCALAR); hdf5_attribute = H5Acreate(handle, "NumFilesPerSnapshot", H5T_NATIVE_INT, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_INT, &header.num_files); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SCALAR); hdf5_attribute = H5Acreate(handle, "Omega0", H5T_NATIVE_DOUBLE, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_DOUBLE, &header.Omega0); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SCALAR); hdf5_attribute = H5Acreate(handle, "OmegaLambda", H5T_NATIVE_DOUBLE, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_DOUBLE, &header.OmegaLambda); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SCALAR); hdf5_attribute = H5Acreate(handle, "HubbleParam", H5T_NATIVE_DOUBLE, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_DOUBLE, &header.HubbleParam); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SCALAR); hdf5_attribute = H5Acreate(handle, "Flag_Sfr", H5T_NATIVE_INT, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_INT, &header.flag_sfr); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SCALAR); hdf5_attribute = H5Acreate(handle, "Flag_Cooling", H5T_NATIVE_INT, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_INT, &header.flag_cooling); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SCALAR); hdf5_attribute = H5Acreate(handle, "Flag_StellarAge", H5T_NATIVE_INT, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_INT, &header.flag_stellarage); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SCALAR); hdf5_attribute = H5Acreate(handle, "Flag_Metals", H5T_NATIVE_INT, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_INT, &header.flag_metals); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SCALAR); hdf5_attribute = H5Acreate(handle, "Flag_Feedback", H5T_NATIVE_INT, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_INT, &header.flag_feedback); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); header.flag_entropy_instead_u = 0; hdf5_dataspace = H5Screate(H5S_SIMPLE); H5Sset_extent_simple(hdf5_dataspace, 1, adim, NULL); hdf5_attribute = H5Acreate(handle, "Flag_Entropy_ICs", H5T_NATIVE_UINT, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_UINT, &header.flag_entropy_instead_u); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); }
/*------------------------------------------------------------------------- * Function: addrem_records * * Purpose: Adds/removes a specified number of records to random datasets * to the SWMR test file. * * Parameters: hid_t fid * The file ID of the SWMR HDF5 file * * unsigned verbose * Whether or not to emit verbose console messages * * unsigned long nops * # of records to read/write in the datasets * * unsigned long flush_count * # of records to write before flushing the file to disk * * Return: Success: 0 * Failure: -1 * *------------------------------------------------------------------------- */ static int addrem_records(hid_t fid, unsigned verbose, unsigned long nops, unsigned long flush_count) { hid_t tid; /* Datatype ID for records */ hid_t mem_sid; /* Memory dataspace ID */ hsize_t start[2] = {0, 0}, count[2] = {1, 1}; /* Hyperslab selection values */ hsize_t dim[2] = {1, 0}; /* Dataspace dimensions */ symbol_t buf[MAX_SIZE_CHANGE]; /* Write buffer */ H5AC_cache_config_t mdc_config_orig; /* Original metadata cache configuration */ H5AC_cache_config_t mdc_config_cork; /* Corked metadata cache configuration */ unsigned long op_to_flush; /* # of operations before flush */ unsigned long u, v; /* Local index variables */ assert(fid > 0); /* Reset the buffer */ memset(&buf, 0, sizeof(buf)); /* Create a dataspace for the record to add */ if((mem_sid = H5Screate_simple(2, count, NULL)) < 0) return -1; /* Create datatype for appending records */ if((tid = create_symbol_datatype()) < 0) return -1; /* Get the current metadata cache configuration, and set up the corked * configuration */ mdc_config_orig.version = H5AC__CURR_CACHE_CONFIG_VERSION; if(H5Fget_mdc_config(fid, &mdc_config_orig) < 0) return -1; memcpy(&mdc_config_cork, &mdc_config_orig, sizeof(mdc_config_cork)); mdc_config_cork.evictions_enabled = FALSE; mdc_config_cork.incr_mode = H5C_incr__off; mdc_config_cork.flash_incr_mode = H5C_flash_incr__off; mdc_config_cork.decr_mode = H5C_decr__off; /* Add and remove records to random datasets, according to frequency * distribution */ op_to_flush = flush_count; for(u=0; u<nops; u++) { symbol_info_t *symbol; /* Symbol to write record to */ hid_t file_sid; /* Dataset's space ID */ /* Get a random dataset, according to the symbol distribution */ symbol = choose_dataset(); /* Decide whether to shrink or expand, and by how much */ count[1] = (hsize_t)random() % (MAX_SIZE_CHANGE * 2) + 1; if(count[1] > MAX_SIZE_CHANGE) { /* Add records */ count[1] -= MAX_SIZE_CHANGE; /* Set the buffer's IDs (equal to its position) */ for(v=0; v<count[1]; v++) buf[v].rec_id = (uint64_t)symbol->nrecords + (uint64_t)v; /* Set the memory space to the correct size */ if(H5Sset_extent_simple(mem_sid, 2, count, NULL) < 0) return -1; /* Get the coordinates to write */ start[1] = symbol->nrecords; /* Cork the metadata cache, to prevent the object header from being * flushed before the data has been written */ /*if(H5Fset_mdc_config(fid, &mdc_config_cork) < 0) return(-1);*/ /* Extend the dataset's dataspace to hold the new record */ symbol->nrecords+= count[1]; dim[1] = symbol->nrecords; if(H5Dset_extent(symbol->dsid, dim) < 0) return -1; /* Get the dataset's dataspace */ if((file_sid = H5Dget_space(symbol->dsid)) < 0) return -1; /* Choose the last record in the dataset */ if(H5Sselect_hyperslab(file_sid, H5S_SELECT_SET, start, NULL, count, NULL) < 0) return -1; /* Write record to the dataset */ if(H5Dwrite(symbol->dsid, tid, mem_sid, file_sid, H5P_DEFAULT, &buf) < 0) return -1; /* Uncork the metadata cache */ /*if(H5Fset_mdc_config(fid, &mdc_config_orig) < 0) return -1;*/ /* Close the dataset's dataspace */ if(H5Sclose(file_sid) < 0) return -1; } /* end if */ else { /* Shrink the dataset's dataspace */ if(count[1] > symbol->nrecords) symbol->nrecords = 0; else symbol->nrecords -= count[1]; dim[1] = symbol->nrecords; if(H5Dset_extent(symbol->dsid, dim) < 0) return -1; } /* end else */ /* Check for flushing file */ if(flush_count > 0) { /* Decrement count of records to write before flushing */ op_to_flush--; /* Check for counter being reached */ if(0 == op_to_flush) { /* Flush contents of file */ if(H5Fflush(fid, H5F_SCOPE_GLOBAL) < 0) return -1; /* Reset flush counter */ op_to_flush = flush_count; } /* end if */ } /* end if */ } /* end for */ /* Emit informational message */ if(verbose) fprintf(stderr, "Closing datasets\n"); /* Close the datasets */ for(u = 0; u < NLEVELS; u++) for(v = 0; v < symbol_count[u]; v++) if(H5Dclose(symbol_info[u][v].dsid) < 0) return -1; return 0; }
/* * Function: dset_write * Purpose: Write buffer into the dataset. * Return: SUCCESS or FAIL * Programmer: Christian Chilan, April, 2008 * Modifications: */ static herr_t dset_write(int local_dim, file_descr *fd, parameters *parms, void *buffer) { int cur_dim = order[local_dim]-1; int ret_code = SUCCESS; int k; hsize_t dims[MAX_DIMS], maxdims[MAX_DIMS]; hsize_t i; int j; herr_t hrc; /* iterates according to the dimensions in order array */ for (i=0; i < parms->dset_size[cur_dim]; i += parms->buf_size[cur_dim]){ h5offset[cur_dim] = (hssize_t)i; offset[cur_dim] = (HDoff_t)i; if (local_dim > 0){ dset_write(local_dim-1, fd, parms, buffer); }else{ switch (parms->io_type) { case POSIXIO: /* initialize POSIX offset in the buffer */ for(j = 0; j < parms->rank; j++) buf_offset[j] = 0; buf_p = (unsigned char *)buffer; /* write POSIX buffer */ posix_buffer_write(0, fd, parms, buffer); break; case HDF5: /* if dimensions are extendable, extend them as needed during access */ if (parms->h5_use_chunks && parms->h5_extendable) { hrc=H5Sget_simple_extent_dims(h5dset_space_id,dims,maxdims); VRFY((hrc >= 0), "H5Sget_simple_extent_dims"); for (k=0; k < parms->rank; k++){ HDassert(h5offset[k] >= 0); if (dims[k] <= (hsize_t)h5offset[k]) { dims[k] = dims[k]+h5count[k]; hrc=H5Sset_extent_simple(h5dset_space_id,parms->rank,dims,maxdims); VRFY((hrc >= 0), "H5Sset_extent_simple"); hrc=H5Dset_extent(h5ds_id,dims); VRFY((hrc >= 0), "H5Dextend"); } } } /* applies offset */ hrc = H5Soffset_simple(h5dset_space_id, h5offset); VRFY((hrc >= 0), "H5Soffset_simple"); /* Write the buffer out */ hrc=H5Sget_simple_extent_dims(h5dset_space_id,dims,maxdims); hrc = H5Dwrite(h5ds_id, ELMT_H5_TYPE, h5mem_space_id, h5dset_space_id, h5dxpl, buffer); VRFY((hrc >= 0), "H5Dwrite"); break; default: /* unknown request */ HDfprintf(stderr, "Unknown IO type request (%d)\n", (int)parms->io_type); HDassert(0 && "Unknown IO type"); break; } /* switch (parms->io_type) */ } } done: return ret_code; }
bool Hdf5Dataset::saveMap(const VecVecDouble &pose_reach, const VecVecDouble &spheres, const VecDouble &ri, const double resolution) { if(!checkPath(this->path_)) { createPath(this->path_); } const char *filepath = this->path_.c_str(); const char *name = this->filename_.c_str(); char fullpath[100]; strcpy(fullpath, filepath); strcat(fullpath, name); ROS_INFO("Saving map %s", this->filename_.c_str()); this->file_ = H5Fcreate(fullpath, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); this->group_poses_ = H5Gcreate(this->file_, "/Poses", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); this->group_spheres_ = H5Gcreate(this->file_, "/Spheres", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); ROS_INFO("Saving poses in reachability map"); const hsize_t ndims = 2; const hsize_t ncols = 10; int posSize =pose_reach.size(); int chunk_size; int PY = 10; if (posSize % 2) { chunk_size = (posSize / 2) + 1; } else { chunk_size = (posSize / 2); } // Create Dataspace hsize_t dims[ndims] = {0, ncols}; // Starting with an empty buffer hsize_t max_dims[ndims] = {H5S_UNLIMITED, ncols}; // Creating dataspace hid_t file_space = H5Screate_simple(ndims, dims, max_dims); // Create Dataset Property list hid_t plist = H5Pcreate(H5P_DATASET_CREATE); H5Pset_layout(plist, H5D_CHUNKED); hsize_t chunk_dims[ndims] = {chunk_size, ncols}; H5Pset_chunk(plist, ndims, chunk_dims); // Create the datset this->poses_dataset_ = H5Dcreate(this->group_poses_, "poses_dataset", H5T_NATIVE_FLOAT, file_space, H5P_DEFAULT, plist, H5P_DEFAULT); // Closing resources H5Pclose(plist); H5Sclose(file_space); // Creating the first buffer hsize_t nlines = chunk_size; float *buffer = new float[nlines * ncols]; float **dset1_data = new float *[nlines]; for (hsize_t i = 0; i < nlines; ++i) { dset1_data[i] = &buffer[i * ncols]; } // Data for the first chunk for (int i = 0; i < chunk_size; i++) { for (int j = 0; j < PY; j++) { dset1_data[i][j] = pose_reach[i][j]; } } // Memory dataspace indicating size of the buffer dims[0] = chunk_size; dims[1] = ncols; hid_t mem_space = H5Screate_simple(ndims, dims, NULL); // Extending dataset dims[0] = chunk_size; dims[1] = ncols; H5Dset_extent(this->poses_dataset_, dims); // Selecting hyperslab on the dataset file_space = H5Dget_space(this->poses_dataset_); hsize_t start[2] = {0, 0}; hsize_t count[2] = {chunk_size, ncols}; H5Sselect_hyperslab(file_space, H5S_SELECT_SET, start, NULL, count, NULL); // Writing buffer to the dataset H5Dwrite(this->poses_dataset_, H5T_NATIVE_FLOAT, mem_space, file_space, H5P_DEFAULT, buffer); // Closing file dataspace H5Sclose(file_space); // Data for the Second chunk for (int i = chunk_size; i < posSize; i++) { for (int j = 0; j < PY; j++) { dset1_data[i - chunk_size][j] = pose_reach[i][j]; } } // Resizing new memory dataspace indicating new size of the buffer dims[0] = posSize - chunk_size; dims[1] = ncols; H5Sset_extent_simple(mem_space, ndims, dims, NULL); // Extend dataset dims[0] = posSize; dims[1] = ncols; H5Dset_extent(this->poses_dataset_, dims); // Selecting hyperslab file_space = H5Dget_space(this->poses_dataset_); start[0] = chunk_size; start[1] = 0; count[0] = posSize - chunk_size; count[1] = ncols; H5Sselect_hyperslab(file_space, H5S_SELECT_SET, start, NULL, count, NULL); // Writing buffer to dataset H5Dwrite(this->poses_dataset_, H5T_NATIVE_FLOAT, mem_space, file_space, H5P_DEFAULT, buffer); // Closing all the resources delete[] dset1_data; delete[] buffer; // Creating Sphere dataset ROS_INFO("Saving spheres in Reachability map"); hid_t sphere_dataspace; const int SX = spheres.size(); const int SY = 4; hsize_t dims2[2]; // dataset dimensions dims2[0] = SX; dims2[1] = SY; double dset2_data[SX][SY]; for(int i=0;i<spheres.size();++i) { for(int j=0;j<spheres[i].size();++j) { dset2_data[i][j] = spheres[i][j]; } for (int j = 3; j < SY; j++) { dset2_data[i][j] = ri[i]; } } sphere_dataspace = H5Screate_simple(2, dims2, NULL); this->sphere_dataset_ = H5Dcreate2(this->group_spheres_, "sphere_dataset", H5T_NATIVE_DOUBLE, sphere_dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Dwrite(this->sphere_dataset_, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset2_data); // Creating attribute hsize_t attr_dims; float attr_data[1]; attr_data[0] = resolution; attr_dims = 1; sphere_dataspace = H5Screate_simple(1, &attr_dims, NULL); this->attr_ = H5Acreate2(this->sphere_dataset_, "Resolution", H5T_NATIVE_FLOAT, sphere_dataspace, H5P_DEFAULT, H5P_DEFAULT); H5Awrite(this->attr_, H5T_NATIVE_FLOAT, attr_data); //H5Aclose(this->attr_); // Closing all H5Sclose(sphere_dataspace); H5Sclose(file_space); H5Sclose(mem_space); close(); }
int main (void) { hid_t file, dataset; /* File and dataset identifiers */ hid_t fid; /* Dataspace identifier */ hid_t attr1, attr2, attr3; /* Attribute identifiers */ hid_t attr; hid_t aid1, aid2, aid3; /* Attribute dataspace identifiers */ hid_t atype, atype_mem; /* Attribute type */ H5T_class_t type_class; hsize_t fdim[] = {SIZE}; hsize_t adim[] = {ADIM1, ADIM2}; /* Dimensions of the first attribute */ float matrix[ADIM1][ADIM2]; /* Attribute data */ herr_t ret; /* Return value */ H5O_info_t oinfo; /* Object info */ unsigned i, j; /* Counters */ char string_out[80]; /* Buffer to read string attribute back */ int point_out; /* Buffer to read scalar attribute back */ /* * Data initialization. */ int vector[] = {1, 2, 3, 4, 5, 6, 7}; /* Dataset data */ int point = 1; /* Value of the scalar attribute */ char string[] = "ABCD"; /* Value of the string attribute */ for (i=0; i < ADIM1; i++) { /* Values of the array attribute */ for (j=0; j < ADIM2; j++) matrix[i][j] = -1.; } /* * Create a file. */ file = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); /* * Create the dataspace for the dataset in the file. */ fid = H5Screate(H5S_SIMPLE); ret = H5Sset_extent_simple(fid, RANK, fdim, NULL); /* * Create the dataset in the file. */ dataset = H5Dcreate2(file, "Dataset", H5T_NATIVE_INT, fid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); /* * Write data to the dataset. */ ret = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL , H5S_ALL, H5P_DEFAULT, vector); /* * Create dataspace for the first attribute. */ aid1 = H5Screate(H5S_SIMPLE); ret = H5Sset_extent_simple(aid1, ARANK, adim, NULL); /* * Create array attribute. */ attr1 = H5Acreate2(dataset, ANAME, H5T_NATIVE_FLOAT, aid1, H5P_DEFAULT, H5P_DEFAULT); /* * Write array attribute. */ ret = H5Awrite(attr1, H5T_NATIVE_FLOAT, matrix); /* * Create scalar attribute. */ aid2 = H5Screate(H5S_SCALAR); attr2 = H5Acreate2(dataset, "Integer attribute", H5T_NATIVE_INT, aid2, H5P_DEFAULT, H5P_DEFAULT); /* * Write scalar attribute. */ ret = H5Awrite(attr2, H5T_NATIVE_INT, &point); /* * Create string attribute. */ aid3 = H5Screate(H5S_SCALAR); atype = H5Tcopy(H5T_C_S1); H5Tset_size(atype, 5); H5Tset_strpad(atype,H5T_STR_NULLTERM); attr3 = H5Acreate2(dataset, ANAMES, atype, aid3, H5P_DEFAULT, H5P_DEFAULT); /* * Write string attribute. */ ret = H5Awrite(attr3, atype, string); /* * Close attribute and file dataspaces, and datatype. */ ret = H5Sclose(aid1); ret = H5Sclose(aid2); ret = H5Sclose(aid3); ret = H5Sclose(fid); ret = H5Tclose(atype); /* * Close the attributes. */ ret = H5Aclose(attr1); ret = H5Aclose(attr2); ret = H5Aclose(attr3); /* * Close the dataset. */ ret = H5Dclose(dataset); /* * Close the file. */ ret = H5Fclose(file); /* * Reopen the file. */ file = H5Fopen(H5FILE_NAME, H5F_ACC_RDONLY, H5P_DEFAULT); /* * Open the dataset. */ dataset = H5Dopen2(file, "Dataset", H5P_DEFAULT); /* * Attach to the scalar attribute using attribute name, then read and * display its value. */ attr = H5Aopen(dataset, "Integer attribute", H5P_DEFAULT); ret = H5Aread(attr, H5T_NATIVE_INT, &point_out); printf("The value of the attribute \"Integer attribute\" is %d \n", point_out); ret = H5Aclose(attr); /* * Find string attribute by iterating through all attributes */ ret = H5Oget_info(dataset, &oinfo); for(i = 0; i < (unsigned)oinfo.num_attrs; i++) { attr = H5Aopen_by_idx(dataset, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)i, H5P_DEFAULT, H5P_DEFAULT); atype = H5Aget_type(attr); type_class = H5Tget_class(atype); if (type_class == H5T_STRING) { atype_mem = H5Tget_native_type(atype, H5T_DIR_ASCEND); ret = H5Aread(attr, atype_mem, string_out); printf("Found string attribute; its index is %d , value = %s \n", i, string_out); ret = H5Tclose(atype_mem); } ret = H5Aclose(attr); ret = H5Tclose(atype); } /* * Get attribute info using iteration function. */ ret = H5Aiterate2(dataset, H5_INDEX_NAME, H5_ITER_INC, NULL, attr_info, NULL); /* * Close the dataset and the file. */ H5Dclose(dataset); H5Fclose(file); return 0; }
int gal2gad2(NbodyModel *theModel, const char * prefix, const char * path, double length, double mass, double velocity) { #ifdef HAS_HDF5 int n=theModel->n; hid_t file_id,group_id,header_id; hid_t hdf5_dataspace,hdf5_attribute; hsize_t pdims[2]; hsize_t mdims[1]; hsize_t tdims[1]; hsize_t fdims[1]; float *positions; float *velocities; int *IDs; int nFiles=1; int Npart[6]={0,0,0,0,n,0}; int Npart_hw[6]={0,0,0,0,0,0}; float *masses; herr_t status; int i_zero=0; double d_zero=0.0; double d_one=1.0; int i; char hdf5file[100]; char paramfile[100]; FILE * pfile; sprintf(hdf5file,"%s%s.hdf5",path,prefix); sprintf(paramfile,"%s%s.param",path,prefix); positions = (float *)malloc(sizeof(float)*3*n); velocities = (float *)malloc(sizeof(float)*3*n); masses = (float *)malloc(sizeof(float)*n); IDs = (int *)malloc(sizeof(int)*n); printf("HDF5FILE BEING GENERATED\n"); for(i=0;i<n;i++) { positions[i*3+0] = (float)theModel->x[i]; positions[i*3+1] = (float)theModel->y[i]; positions[i*3+2] = (float)theModel->z[i]; velocities[i*3+0] = (float)theModel->vx[i]; velocities[i*3+1] = (float)theModel->vy[i]; velocities[i*3+2] = (float)theModel->vz[i]; masses[i] = (float)theModel->mass[i]; IDs[i]=i; } file_id = H5Fcreate (hdf5file, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); group_id = H5Gcreate1(file_id, "PartType4", 0); header_id = H5Gcreate1(file_id, "Header", 0); pdims[0] = n; pdims[1] = 3; mdims[0] = n; tdims[0] = 6; fdims[0] = 1; hdf5_dataspace = H5Screate(H5S_SIMPLE); H5Sset_extent_simple(hdf5_dataspace, 1, tdims, NULL); hdf5_attribute = H5Acreate1(header_id, "NumPart_ThisFile", H5T_NATIVE_INT, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_INT, Npart); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SIMPLE); H5Sset_extent_simple(hdf5_dataspace, 1, tdims, NULL); hdf5_attribute = H5Acreate1(header_id, "NumPart_Total", H5T_NATIVE_UINT, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_UINT, Npart); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SIMPLE); H5Sset_extent_simple(hdf5_dataspace, 1, tdims, NULL); hdf5_attribute = H5Acreate1(header_id, "NumPart_Total_HW", H5T_NATIVE_UINT, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_UINT, Npart_hw); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SCALAR); hdf5_attribute = H5Acreate1(header_id, "Time", H5T_NATIVE_DOUBLE, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_DOUBLE, &time); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SCALAR); hdf5_attribute = H5Acreate1(header_id, "Redshift", H5T_NATIVE_DOUBLE, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_DOUBLE, &d_zero); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SCALAR); hdf5_attribute = H5Acreate1(header_id, "BoxSize", H5T_NATIVE_DOUBLE, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_DOUBLE, &d_zero); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SCALAR); hdf5_attribute = H5Acreate1(header_id, "NumFilesPerSnapshot", H5T_NATIVE_INT, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_INT, &nFiles); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SCALAR); hdf5_attribute = H5Acreate1(header_id, "Omega0", H5T_NATIVE_DOUBLE, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_DOUBLE, &d_zero); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SCALAR); hdf5_attribute = H5Acreate1(header_id, "OmegaLambda", H5T_NATIVE_DOUBLE, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_DOUBLE, &d_zero); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SCALAR); hdf5_attribute = H5Acreate1(header_id, "HubbleParam", H5T_NATIVE_DOUBLE, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_DOUBLE, &d_one); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SCALAR); hdf5_attribute = H5Acreate1(header_id, "Flag_Sfr", H5T_NATIVE_INT, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_INT, &i_zero); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SCALAR); hdf5_attribute = H5Acreate1(header_id, "Flag_Cooling", H5T_NATIVE_INT, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_INT, &i_zero); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SCALAR); hdf5_attribute = H5Acreate1(header_id, "Flag_StellarAge", H5T_NATIVE_INT, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_INT, &i_zero); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SCALAR); hdf5_attribute = H5Acreate1(header_id, "Flag_Metals", H5T_NATIVE_INT, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_INT, &i_zero); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SCALAR); hdf5_attribute = H5Acreate1(header_id, "Flag_Feedback", H5T_NATIVE_INT, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_INT, &i_zero); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SIMPLE); H5Sset_extent_simple(hdf5_dataspace, 1, tdims, NULL); hdf5_attribute = H5Acreate1(header_id, "Flag_Entropy_ICs", H5T_NATIVE_UINT, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_UINT, Npart_hw); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); status = H5LTmake_dataset(file_id,"PartType4/Coordinates",2, pdims,H5T_NATIVE_FLOAT,positions); status = H5LTmake_dataset(file_id,"PartType4/ParticleIDs",1, mdims,H5T_NATIVE_UINT,IDs); status = H5LTmake_dataset(file_id,"PartType4/Velocities",2, pdims,H5T_NATIVE_FLOAT,velocities); status = H5LTmake_dataset(file_id,"PartType4/Masses",1, mdims,H5T_NATIVE_FLOAT,masses); status = H5Fclose (file_id); free(positions); free(velocities); free(masses); free(IDs); pfile = fopen(paramfile,"w"); fprintf(pfile,"InitCondFile\t%s\n",prefix); fprintf(pfile,"OutputDir\tout\n"); fprintf(pfile,"EnergyFile\tenergy.txt\n"); fprintf(pfile,"InfoFile\tinfo.txt\n"); fprintf(pfile,"TimingsFile\ttimings.txt\n"); fprintf(pfile,"CpuFile\tcpu.txt\n"); fprintf(pfile,"RestartFile\trestart\n"); fprintf(pfile,"SnapshotFileBase\tsnapshot\n"); fprintf(pfile,"OutputListFilename\toutput_list.txt\n"); fprintf(pfile,"ICFormat\t3\n"); fprintf(pfile,"SnapFormat\t3\n"); fprintf(pfile,"TypeOfTimestepCriterion\t0\n"); fprintf(pfile,"OutputListOn\t0\n"); fprintf(pfile,"PeriodicBoundariesOn\t0\n"); fprintf(pfile,"TimeBegin\t0.0\n"); fprintf(pfile,"TimeMax\t%le\n",theModel->tFinal); fprintf(pfile,"Omega0\t0\n"); fprintf(pfile,"OmegaLambda\t0\n"); fprintf(pfile,"OmegaBaryon\t0\n"); fprintf(pfile,"HubbleParam\t1.0\n"); fprintf(pfile,"BoxSize\t0\n"); fprintf(pfile,"TimeBetSnapshot\t%le\n",theModel->tFinal/100); //change this fprintf(pfile,"TimeOfFirstSnapshot\t0\n"); fprintf(pfile,"CpuTimeBetRestartFile\t300.0\n"); fprintf(pfile,"TimeBetStatistics\t0.1\n"); fprintf(pfile,"NumFilesPerSnapshot\t1\n"); fprintf(pfile,"NumFilesWrittenInParallel\t1\n"); fprintf(pfile,"ErrTolIntAccuracy\t0.0025\n"); fprintf(pfile,"CourantFac\t0.15\n"); fprintf(pfile,"MaxSizeTimestep\t0.01\n"); fprintf(pfile,"MinSizeTimestep\t0.0\n"); fprintf(pfile,"ErrTolTheta\t0.05\n"); fprintf(pfile,"TypeOfOpeningCriterion\t1\n"); fprintf(pfile,"ErrTolForceAcc\t0.0005\n"); fprintf(pfile,"TreeDomainUpdateFrequency\t0.01\n"); fprintf(pfile,"DesNumNgb\t50\n"); fprintf(pfile,"MaxNumNgbDeviation\t2\n"); fprintf(pfile,"ArtBulkViscConst\t0.8\n"); fprintf(pfile,"InitGasTemp\t0\n"); fprintf(pfile,"MinGasTemp\t0\n"); fprintf(pfile,"PartAllocFactor\t1.5\n"); fprintf(pfile,"TreeAllocFactor\t0.8\n"); fprintf(pfile,"BufferSize\t25\n"); fprintf(pfile,"UnitLength_in_cm\t%le \n",length); fprintf(pfile,"UnitMass_in_g\t%le \n",mass); fprintf(pfile,"UnitVelocity_in_cm_per_s\t%le \n",velocity); fprintf(pfile,"GravityConstantInternal\t0\n"); fprintf(pfile,"MinGasHsmlFractional\t0.25\n"); fprintf(pfile,"SofteningGas\t0\n"); fprintf(pfile,"SofteningHalo\t1.0\n"); fprintf(pfile,"SofteningDisk\t0.4\n"); fprintf(pfile,"SofteningBulge\t0\n"); fprintf(pfile,"SofteningStars\t1.0e-2\n"); fprintf(pfile,"SofteningBndry\t0\n"); fprintf(pfile,"SofteningGasMaxPhys\t0\n"); fprintf(pfile,"SofteningHaloMaxPhys\t1.0\n"); fprintf(pfile,"SofteningDiskMaxPhys\t0.4\n"); fprintf(pfile,"SofteningBulgeMaxPhys\t0\n"); fprintf(pfile,"SofteningStarsMaxPhys\t1.0e-2\n"); fprintf(pfile,"SofteningBndryMaxPhys\t0\n"); fprintf(pfile,"MaxRMSDisplacementFac\t0.2\n"); fprintf(pfile,"TimeLimitCPU\t36000\n"); fprintf(pfile,"ResubmitOn\t0\n"); fprintf(pfile,"ResubmitCommand\tmy-scriptfile\n"); fprintf(pfile,"ComovingIntegrationOn\t0\n"); fclose(pfile); return 0; #else printf("ATTEMTPING TO RUN GAL2GAD2 ROUTINE WITHOUT HDF5 SUPPORT!\n"); printf("EXITING!\n"); exit(0); return 1; #endif }
int main( int argc, char ** argv ) { hid_t file_id,group_id,header_id; hid_t hdf5_dataspace,hdf5_attribute; hsize_t pdims[2]; hsize_t mdims[1]; hsize_t tdims[1]; hsize_t fdims[1]; float positions[NPARTS*NDIMS]; float velocities[NPARTS*NDIMS]; int IDs[NPARTS]; int nFiles=1; int Npart[NTYPES]={0,0,0,0,NPARTS,0}; int Npart_hw[NTYPES]={0,0,0,0,0,0}; #ifdef HAS_CORE double core_fraction=0.1; double disk_mass=(1.0-core_fraction)*(500*400/1.0e10); double core_mass=disk_mass*core_fraction/(1.0-core_fraction); double mass_per=disk_mass/(NPARTS-1); #else double disk_mass=(500*400/1.0e10); double mass_per=disk_mass/(NPARTS); #endif //double Massarr[NTYPES]={0.0,0.0,0.0,0.0,mass_per,0.0}; float masses[NPARTS]; herr_t status; double redshift=0.0; double time=0.0; double boxsize=0.0; double dzero=0.0; double done=1.0; int izero=0; int ione=1; double distance; double radius=0.77; double base_vel=0.0; double r,rscaled,a,v,cosine,sine,con,posx,posy; double rotate_factor=1.0; double G=6.67e-8; // cm^3 g^-1 s^-2 char filename[80]; int i,j,k; seed_by_time(0); if (argc>1) { sscanf(argv[1],"%s",filename); } else { strcpy(filename,"gal_test.hdf5"); } #ifdef HAS_CORE masses[0]=core_mass; for(i=1;i<NPARTS;i++) { masses[i]=mass_per; } #else for(i=0;i<NPARTS;i++) { masses[i]=mass_per; } #endif positions[0]=0.0; positions[1]=0.0; positions[2]=0.0; for(i=1;i<NPARTS;i++) { distance=2.0*radius; while(distance>radius) { distance=0.0; for(j=0;j<NDIMS;j++) { positions[3*i+j] = radius*(1.0-2.0*(double)rand()/(double)RAND_MAX); distance+=pow(positions[3*i+j],2.0); } distance=sqrt(distance); } } /* random velocity for(i=0;i<NPARTS;i++) { for(j=0;j<NDIMS;j++) { velocities[3*i+j] = base_vel*(1.0-2.0*(double)rand()/(double)RAND_MAX); } } */ velocities[0]=0.0; velocities[1]=0.0; velocities[2]=0.0; for(i=1;i<NPARTS;i++) { posx = positions[NDIMS*i]; posy = positions[NDIMS*i+1]; r=sqrt(pow(posx,2.0)+pow(posy,2.0)); #ifdef HAS_CORE con = G*(disk_mass+core_mass)*1.99e43*pow((r/radius),3.0); #else con = G*(disk_mass)*1.99e43*pow((r/radius),3.0); #endif rscaled=r*3.089e21; // convert to cm if(r>0.0) { v=sqrt(con/rscaled)*1.0e-5; cosine=posx/r; sine=posy/r; velocities[NDIMS*i+0]=v*rotate_factor*(-sine); velocities[NDIMS*i+1]=v*rotate_factor*cosine; velocities[NDIMS*i+2]=0.0; } } for(i=0;i<NPARTS;i++) { IDs[i]=i; } // EXAMPLE("make a dataset"); file_id = H5Fcreate (filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); group_id = H5Gcreate(file_id, "PartType4", 0); header_id = H5Gcreate(file_id, "Header", 0); pdims[0] = NPARTS; pdims[1] = NDIMS; mdims[0] = NPARTS; tdims[0] = NTYPES; fdims[0] = 1; hdf5_dataspace = H5Screate(H5S_SIMPLE); H5Sset_extent_simple(hdf5_dataspace, 1, tdims, NULL); hdf5_attribute = H5Acreate(header_id, "NumPart_ThisFile", H5T_NATIVE_INT, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_INT, Npart); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SIMPLE); H5Sset_extent_simple(hdf5_dataspace, 1, tdims, NULL); hdf5_attribute = H5Acreate(header_id, "NumPart_Total", H5T_NATIVE_UINT, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_UINT, Npart); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SIMPLE); H5Sset_extent_simple(hdf5_dataspace, 1, tdims, NULL); hdf5_attribute = H5Acreate(header_id, "NumPart_Total_HW", H5T_NATIVE_UINT, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_UINT, Npart_hw); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); /* hdf5_dataspace = H5Screate(H5S_SIMPLE); H5Sset_extent_simple(hdf5_dataspace, 1, tdims, NULL); hdf5_attribute = H5Acreate(header_id, "MassTable", H5T_NATIVE_DOUBLE, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_DOUBLE, Massarr); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); */ hdf5_dataspace = H5Screate(H5S_SCALAR); hdf5_attribute = H5Acreate(header_id, "Time", H5T_NATIVE_DOUBLE, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_DOUBLE, &time); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SCALAR); hdf5_attribute = H5Acreate(header_id, "Redshift", H5T_NATIVE_DOUBLE, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_DOUBLE, &redshift); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SCALAR); hdf5_attribute = H5Acreate(header_id, "BoxSize", H5T_NATIVE_DOUBLE, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_DOUBLE, &boxsize); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SCALAR); hdf5_attribute = H5Acreate(header_id, "NumFilesPerSnapshot", H5T_NATIVE_INT, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_INT, &nFiles); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SCALAR); hdf5_attribute = H5Acreate(header_id, "Omega0", H5T_NATIVE_DOUBLE, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_DOUBLE, &dzero); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SCALAR); hdf5_attribute = H5Acreate(header_id, "OmegaLambda", H5T_NATIVE_DOUBLE, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_DOUBLE, &dzero); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SCALAR); hdf5_attribute = H5Acreate(header_id, "HubbleParam", H5T_NATIVE_DOUBLE, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_DOUBLE, &done); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SCALAR); hdf5_attribute = H5Acreate(header_id, "Flag_Sfr", H5T_NATIVE_INT, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_INT, &izero); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SCALAR); hdf5_attribute = H5Acreate(header_id, "Flag_Cooling", H5T_NATIVE_INT, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_INT, &izero); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SCALAR); hdf5_attribute = H5Acreate(header_id, "Flag_StellarAge", H5T_NATIVE_INT, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_INT, &izero); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SCALAR); hdf5_attribute = H5Acreate(header_id, "Flag_Metals", H5T_NATIVE_INT, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_INT, &izero); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SCALAR); hdf5_attribute = H5Acreate(header_id, "Flag_Feedback", H5T_NATIVE_INT, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_INT, &izero); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); hdf5_dataspace = H5Screate(H5S_SIMPLE); H5Sset_extent_simple(hdf5_dataspace, 1, tdims, NULL); hdf5_attribute = H5Acreate(header_id, "Flag_Entropy_ICs", H5T_NATIVE_UINT, hdf5_dataspace, H5P_DEFAULT); H5Awrite(hdf5_attribute, H5T_NATIVE_UINT, Npart_hw); H5Aclose(hdf5_attribute); H5Sclose(hdf5_dataspace); status = H5LTmake_dataset(file_id,"PartType4/Coordinates",2, pdims,H5T_NATIVE_FLOAT,positions); status = H5LTmake_dataset(file_id,"PartType4/ParticleIDs",1, mdims,H5T_NATIVE_UINT,IDs); status = H5LTmake_dataset(file_id,"PartType4/Velocities",2, pdims,H5T_NATIVE_FLOAT,velocities); status = H5LTmake_dataset(file_id,"PartType4/Masses",1, mdims,H5T_NATIVE_FLOAT,masses); status = H5Fclose (file_id); // PASSED(); return 0; }