extern "C" bool write_h5(char* fname, dtype* data_array){ #ifdef _HDF5_H hid_t out_type_id = H5T_NATIVE_FLOAT; hid_t file_id = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); hid_t dataspace_id, dataset_id; int ndims = 2; hsize_t dimsH[2]; dimsH[0] = 1679; dimsH[1] = 1475; hid_t gid2 = H5Gcreate1(file_id,"data",0); dataspace_id = H5Screate_simple(ndims, dimsH, NULL); bool compress = false; hid_t dcpl = H5Pcreate (H5P_DATASET_CREATE); hsize_t chunk[2] = {64, 64}; if (compress) { H5Pset_deflate (dcpl, 9); H5Pset_chunk (dcpl, 2, chunk); } dataset_id = H5Dcreate(file_id, "/data/data", out_type_id, dataspace_id, H5P_DEFAULT, dcpl, H5P_DEFAULT); H5Dwrite(dataset_id, out_type_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, data_array); H5Dclose(dataset_id); H5Sclose(dataspace_id); H5Gclose(gid2); H5Fclose(file_id); return true; #endif return false; }
// save the population void logger_save_population(logger_t *logger, GString *profiles, GString *hosts) { // create population group hid_t group_id; group_id = H5Gcreate1(logger->file_id, "/population", H5P_DEFAULT); H5LTmake_dataset_string(group_id, "/population/profiles", profiles->str); H5LTmake_dataset_string(group_id, "/population/hosts", hosts->str); H5Gclose(group_id); }
/*------------------------------------------------------------------------- * * Function: group_version_macros * * Purpose: Test H5G version compatibility macros. * * Return: Success: 0 * Failure: -1 * * Programmer: Neil Fortner * Saturday, October 11, 2008 * *------------------------------------------------------------------------- */ static int group_version_macros(hid_t fapl) { hid_t fid, gid; char filename[NAME_BUF_SIZE]; /* Output message about test being performed */ TESTING("H5G version compatibility macros"); /* Create file */ h5_fixname(FILENAME[1], fapl, filename, sizeof filename); if ((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR; /* Create a group (test H5Gcreate1) */ if ((gid = H5Gcreate1(fid, "group", 0)) < 0) TEST_ERROR; /* Close group */ if (H5Gclose(gid) < 0) TEST_ERROR; /* Open group (test H5Gopen1) */ if ((gid = H5Gopen1(fid, "group")) < 0) TEST_ERROR; /* Close group */ if (H5Gclose(gid) < 0) TEST_ERROR; /* Close file */ if (H5Fclose(fid) < 0) TEST_ERROR; PASSED(); return 0; error: H5E_BEGIN_TRY { H5Fclose(gid); H5Gclose(fid); } H5E_END_TRY return -1; } /* end group_version_macros() */
void logger_write_params(logger_t *logger) { // create settings group hid_t group_id = H5Gcreate1(logger->file_id, "/settings", H5P_DEFAULT); H5Gclose(group_id); // create dataspace hsize_t dim = 1; H5LTmake_dataset(logger->file_id, "/settings/psize", 1, &dim, H5T_NATIVE_INT, &logger->params->psize); H5LTmake_dataset(logger->file_id, "/settings/steps", 1, &dim, H5T_NATIVE_INT, &logger->params->steps); H5LTmake_dataset(logger->file_id, "/settings/fparts", 1, &dim, H5T_NATIVE_INT, &logger->params->fparts); H5LTmake_dataset(logger->file_id, "/settings/seed", 1, &dim, H5T_NATIVE_INT, &logger->params->seed); H5LTmake_dataset(logger->file_id, "/settings/seg_type", 1, &dim, H5T_NATIVE_INT, &logger->params->seg_type); H5LTmake_dataset(logger->file_id, "/settings/mu", 1, &dim, H5T_NATIVE_DOUBLE, &logger->params->mu); H5LTmake_dataset(logger->file_id, "/settings/pconj", 1, &dim, H5T_NATIVE_DOUBLE, &logger->params->pconj); H5LTmake_dataset(logger->file_id, "/settings/beta", 1, &dim, H5T_NATIVE_DOUBLE, &logger->params->beta); H5LTmake_dataset(logger->file_id, "/settings/kappa", 1, &dim, H5T_NATIVE_DOUBLE, &logger->params->kappa); H5LTmake_dataset(logger->file_id, "/settings/alpha", 1, &dim, H5T_NATIVE_DOUBLE, &logger->params->alpha); H5LTmake_dataset(logger->file_id, "/settings/max_beta", 1, &dim, H5T_NATIVE_DOUBLE, &logger->params->max_beta); H5LTmake_dataset(logger->file_id, "/settings/max_kappa", 1, &dim, H5T_NATIVE_DOUBLE, &logger->params->max_kappa); H5LTmake_dataset(logger->file_id, "/settings/max_alpha", 1, &dim, H5T_NATIVE_DOUBLE, &logger->params->max_alpha); H5LTmake_dataset(logger->file_id, "/settings/max_cn", 1, &dim, H5T_NATIVE_INT, &logger->params->max_cn); H5LTmake_dataset(logger->file_id, "/settings/phi", 1, &dim, H5T_NATIVE_DOUBLE, &logger->params->phi); H5LTmake_dataset(logger->file_id, "/settings/gamma", 1, &dim, H5T_NATIVE_DOUBLE, &logger->params->gamma); H5LTmake_dataset(logger->file_id, "/settings/gamma.alpha", 1, &dim, H5T_NATIVE_DOUBLE, &logger->params->gamma_alpha); H5LTmake_dataset(logger->file_id, "/settings/lambda", 1, &dim, H5T_NATIVE_DOUBLE, &logger->params->lambda); H5LTmake_dataset(logger->file_id, "/settings/omega.0", 1, &dim, H5T_NATIVE_DOUBLE, &logger->params->omega_0); H5LTmake_dataset(logger->file_id, "/settings/dilution", 1, &dim, H5T_NATIVE_INT, &logger->params->dilution); H5LTmake_dataset(logger->file_id, "/settings/mut.rng", 1, &dim, H5T_NATIVE_DOUBLE, &logger->params->mut_rng); H5LTmake_dataset(logger->file_id, "/settings/duration", 1, &dim, H5T_NATIVE_DOUBLE, &logger->params->duration); }
// create groups -- then create tseriess logger_t *logger_new(params_t *params) { logger_t *logger = malloc(sizeof(logger_t)); // store params logger->params = params; // open file logger->file_id = H5Fcreate(params->log_path->str, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); // initialize inter- stats logger->inter_stats = nvar_init(P_INTER_IDX_ALL); // reset counters memset(&logger->counters, 0, sizeof(counters_t)); // create group of dynamics hid_t group_id = H5Gcreate1(logger->file_id, "/dynamics", H5P_DEFAULT); H5Gclose(group_id); // ================== CREATE TABLES =================== // create COUNTERS table const char *counter_labels[] = {"n", "cn", "inf", "ptypes", "loss", "div.inf", "div.all", "death", "rep", "ht", "mut"}; hdf_table_initialize(&logger->tbl_counters, logger->file_id, "/dynamics/counters", TBL_COUNTERS_LEN, Q_HDF_TYPE_INT, counter_labels); // create COMPETITION data?? if (logger->params->compete) { // create competition group group_id = H5Gcreate1(logger->file_id, "/competition", H5P_DEFAULT); H5Gclose(group_id); hdf_table_initialize(&logger->tbl_competition, logger->file_id, "/competition/frequencies", params->contenders, Q_HDF_TYPE_INT, NULL); // create contenders group group_id = H5Gcreate1(logger->file_id, "/competition/contenders", H5P_DEFAULT); H5Gclose(group_id); // write all the contenders in the group const char *labels[] = {"beta", "kappa", "alpha"}; double data[3]; GHashTableIter iter; profile_t *profile; pdata_t *pdata; GString *name; hdf_table_t table; g_hash_table_iter_init(&iter, params->pool->profiles); while (g_hash_table_iter_next(&iter, (void **)&profile, (void **)&pdata)) { assert(pdata->pid < params->contenders); // convert profile id to a string name = g_string_new_itol(pdata->pid); g_string_prepend(name, "/competition/contenders/"); // get data into buffer data[0] = profile->beta; data[1] = profile->kappa; data[2] = profile->alpha; // create table in group contenders hdf_table_initialize(&table, logger->file_id, name->str, 3, Q_HDF_TYPE_DOUBLE, labels); hdf_table_append_record(&table, data); hdf_table_finalize(&table); // free string g_string_free(name, TRUE); } } nvar_t *nvar; // create INTER tables group_id = H5Gcreate1(logger->file_id, "/dynamics/inter", H5P_DEFAULT); H5Gclose(group_id); const char *inter_m_labels[] = {"domg", "cn", "dev", "absdev", "beta", "kappa", "alpha", "bk", "rate", "nr", "ht", "death", "fitness", "tbeta", "tkappa", "talpha", "tbk"}; hdf_table_initialize(&logger->tbl_inter_m, logger->file_id, "/dynamics/inter/M", P_INTER_IDX_ALL, Q_HDF_TYPE_DOUBLE, inter_m_labels); hdf_table_initialize(&logger->tbl_inter_v, logger->file_id, "/dynamics/inter/V", P_INTER_IDX_ALL, Q_HDF_TYPE_DOUBLE, inter_m_labels); // create an nvar object (just to get the covariance labels) nvar = nvar_init(P_INTER_IDX_ALL); nvar_assign_labels(nvar, inter_m_labels); hdf_table_initialize(&logger->tbl_inter_c, logger->file_id, "/dynamics/inter/C", P_INTER_IDX_ALL*(P_INTER_IDX_ALL-1)/2, Q_HDF_TYPE_DOUBLE, (const char **)nvar->plabels); nvar_free(nvar); // create INTRA tables group_id = H5Gcreate1(logger->file_id, "/dynamics/intra", H5P_DEFAULT); H5Gclose(group_id); const char *intra_m_labels[] = {"cn", "beta", "kappa", "alpha", "bk", "rate", "nr", "ht", "death", "fitness", "tbeta", "tkappa", "talpha", "tbk"}; hdf_table_initialize(&logger->tbl_intra_m, logger->file_id, "/dynamics/intra/M", P_INTRA_IDX_ALL, Q_HDF_TYPE_DOUBLE, intra_m_labels); hdf_table_initialize(&logger->tbl_intra_v, logger->file_id, "/dynamics/intra/V", P_INTRA_IDX_ALL, Q_HDF_TYPE_DOUBLE, intra_m_labels); // create an nvar object (just to get the covariance labels) nvar = nvar_init(P_INTRA_IDX_ALL); nvar_assign_labels(nvar, intra_m_labels); hdf_table_initialize(&logger->tbl_intra_c, logger->file_id, "/dynamics/intra/C", P_INTRA_IDX_ALL*(P_INTRA_IDX_ALL-1)/2, Q_HDF_TYPE_DOUBLE, (const char **)nvar->plabels); // create GLOBAL tables (all writing occurring within the pool) group_id = H5Gcreate1(logger->file_id, "/dynamics/global", H5P_DEFAULT); H5Gclose(group_id); hdf_table_initialize(&logger->tbl_global_m, logger->file_id, "/dynamics/global/M", P_INTRA_IDX_ALL, Q_HDF_TYPE_DOUBLE, intra_m_labels); hdf_table_initialize(&logger->tbl_global_v, logger->file_id, "/dynamics/global/V", P_INTRA_IDX_ALL, Q_HDF_TYPE_DOUBLE, intra_m_labels); hdf_table_initialize(&logger->tbl_global_c, logger->file_id, "/dynamics/global/C", P_INTRA_IDX_ALL*(P_INTRA_IDX_ALL-1)/2, Q_HDF_TYPE_DOUBLE, (const char **)nvar->plabels); // free the nvar object nvar_free(nvar); // create the RELATEDNESS2 tables group_id = H5Gcreate1(logger->file_id, "/dynamics/relatedness", H5P_DEFAULT); H5Gclose(group_id); group_id = H5Gcreate1(logger->file_id, "/dynamics/relatedness/wg", H5P_DEFAULT); H5Gclose(group_id); group_id = H5Gcreate1(logger->file_id, "/dynamics/relatedness/oo", H5P_DEFAULT); H5Gclose(group_id); const char *relatedness_labels[] = {"beta", "kappa", "alpha"}; hdf_table_initialize(&logger->tbl_relatedness_wg_cov, logger->file_id, "/dynamics/relatedness/wg/cov", P_PARAMS_IDX_ALL, Q_HDF_TYPE_DOUBLE, relatedness_labels); hdf_table_initialize(&logger->tbl_relatedness_wg_var, logger->file_id, "/dynamics/relatedness/wg/var", P_PARAMS_IDX_ALL, Q_HDF_TYPE_DOUBLE, relatedness_labels); hdf_table_initialize(&logger->tbl_relatedness_oo_cov, logger->file_id, "/dynamics/relatedness/oo/cov", P_PARAMS_IDX_ALL, Q_HDF_TYPE_DOUBLE, relatedness_labels); hdf_table_initialize(&logger->tbl_relatedness_oo_var, logger->file_id, "/dynamics/relatedness/oo/var", P_PARAMS_IDX_ALL, Q_HDF_TYPE_DOUBLE, relatedness_labels); // reset the intra-buffers BFILL(logger->MM, P_INTRA_IDX_ALL, 0); BFILL(logger->VV, P_INTRA_IDX_ALL, 0); BFILL(logger->CC, P_INTRA_IDX_ALL * (P_INTRA_IDX_ALL-1) / 2, 0); // === CREATE HISTOGRAMS === // create group group_id = H5Gcreate1(logger->file_id, "/histograms", H5P_DEFAULT); H5Gclose(group_id); // initialize CN histogram double xlim[] = {-0.5, params->max_cn - 0.5}; hdf_histogram_initialize(&logger->hist_cn, logger->file_id, "/histograms/cn", params->fparts, params->max_cn, 0, xlim, NULL, FALSE); // initialize AGE histogram xlim[0] = 0; xlim[1] = 50; hdf_histogram_initialize(&logger->hist_age, logger->file_id, "/histograms/age", params->fparts, 50, 0, xlim, NULL, FALSE); // initialize BK histogram xlim[1] = logger->params->max_beta; double ylim[] = {0, logger->params->max_kappa}; hdf_histogram_initialize(&logger->hist_beta_kappa, logger->file_id, "/histograms/bk", params->fparts, logger->params->nbins, logger->params->nbins, xlim, ylim, TRUE); // initialize BA histogram xlim[0] = 0; xlim[1] = logger->params->max_beta; ylim[0] = 0; ylim[1] = logger->params->max_alpha; hdf_histogram_initialize(&logger->hist_beta_alpha, logger->file_id, "/histograms/ba", params->fparts, logger->params->nbins, logger->params->nbins, xlim, ylim, TRUE); // initialize KA histogram xlim[0] = 0; xlim[1] = logger->params->max_kappa; ylim[0] = 0; ylim[1] = logger->params->max_alpha; hdf_histogram_initialize(&logger->hist_kappa_alpha, logger->file_id, "/histograms/ka", params->fparts, logger->params->nbins, logger->params->nbins, xlim, ylim, TRUE); return logger; }
bool WriteHDF5file(char* fname, dtype* outArray, int* dims, float* pixel, float* expo, float* waveLen, float* dist, float* beamxy, float* flux, bool compress, unsigned short* badmask) { #ifdef _HDF5_H hid_t out_type_id = H5T_NATIVE_FLOAT; hid_t file_id = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); hid_t gid = H5Gcreate1(file_id,"LCLS",0); hid_t dataspace_id, dataset_id; int ndims = 1; hsize_t dimsH[2]; dimsH[0] = 1; dimsH[1] = 0; dataspace_id = H5Screate_simple(1, dimsH, NULL); dataset_id = H5Dcreate1(gid, "detectorPosition", out_type_id, dataspace_id, H5P_DEFAULT); if(H5Dwrite(dataset_id, out_type_id, H5S_ALL, H5S_ALL,H5P_DEFAULT, dist)< 0) printf("Error writing 1D data to file\n"); H5Dclose(dataset_id); dataset_id = H5Dcreate1(gid, "photon_wavelength_A", out_type_id, dataspace_id, H5P_DEFAULT); if(H5Dwrite(dataset_id, out_type_id, H5S_ALL, H5S_ALL,H5P_DEFAULT, waveLen)< 0) printf("Error writing 1D data to file\n"); H5Dclose(dataset_id); dataset_id = H5Dcreate1(gid, "exposure_s", out_type_id, dataspace_id, H5P_DEFAULT); if(H5Dwrite(dataset_id, out_type_id, H5S_ALL, H5S_ALL,H5P_DEFAULT, expo)< 0) printf("Error writing 1D data to file\n"); H5Dclose(dataset_id); dataset_id = H5Dcreate1(gid, "pixelX_m", out_type_id, dataspace_id, H5P_DEFAULT); if(H5Dwrite(dataset_id, out_type_id, H5S_ALL, H5S_ALL,H5P_DEFAULT, &pixel[0])< 0) printf("Error writing 1D data to file\n"); H5Dclose(dataset_id); dataset_id = H5Dcreate1(gid, "pixelY_m", out_type_id, dataspace_id, H5P_DEFAULT); if(H5Dwrite(dataset_id, out_type_id, H5S_ALL, H5S_ALL,H5P_DEFAULT, &pixel[1])< 0) printf("Error writing 1D data to file\n"); H5Dclose(dataset_id); dataset_id = H5Dcreate1(gid, "flux_ph_s", out_type_id, dataspace_id, H5P_DEFAULT); if(H5Dwrite(dataset_id, out_type_id, H5S_ALL, H5S_ALL,H5P_DEFAULT, flux)< 0) printf("Error writing 1D data to file\n"); H5Dclose(dataset_id); dataset_id = H5Dcreate1(gid, "beamX_px", out_type_id, dataspace_id, H5P_DEFAULT); if(H5Dwrite(dataset_id, out_type_id, H5S_ALL, H5S_ALL,H5P_DEFAULT, &beamxy[0])< 0) printf("Error writing 1D data to file\n"); H5Dclose(dataset_id); dataset_id = H5Dcreate1(gid, "beamY_px", out_type_id, dataspace_id, H5P_DEFAULT); if(H5Dwrite(dataset_id, out_type_id, H5S_ALL, H5S_ALL,H5P_DEFAULT, &beamxy[1])< 0) printf("Error writing 1D data to file\n"); H5Dclose(dataset_id); H5Sclose(dataspace_id); ndims = 2; dimsH[0] = dims[1]; dimsH[1] = dims[0]; hid_t gid2 = H5Gcreate1(file_id,"data",0); dataspace_id = H5Screate_simple(ndims, dimsH, NULL); //COMPRESSION hid_t dcpl = H5Pcreate (H5P_DATASET_CREATE); // hsize_t chunk[2] = {dimsH[0], dimsH[1]}; //#ifdef ZLIB_H //CASS hsize_t chunk[2] = {40,2}; hsize_t chunk[2] = {64, 64}; if (compress) { H5Pset_deflate (dcpl, 9); H5Pset_chunk (dcpl, 2, chunk); } //#endif // H5Pset_szip (dcpl, H5_SZIP_NN_OPTION_MASK, 8); // H5Pset_chunk (dcpl, 2, chunk); dataset_id = H5Dcreate(file_id, "/data/data", out_type_id, dataspace_id, H5P_DEFAULT, dcpl, H5P_DEFAULT); // dataset_id = H5Dcreate1(file_id, "/data/data", out_type_id, dataspace_id, H5P_DEFAULT); if(H5Dwrite(dataset_id, out_type_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, outArray)< 0) printf("Error writing 2D data to file\n"); H5Dclose(dataset_id); H5Sclose(dataspace_id); H5Gclose(gid2); //Here badmask H5Gclose(gid); H5Fclose(file_id); return true; #endif return false; }
/* * Write 2D data to HDF5 file */ void cData2d::writeHDF5(char* filename){ // Figure out the HDF5 data type hid_t out_type_id = 0; if(sizeof(tData2d) == sizeof(float)) out_type_id = H5T_NATIVE_FLOAT; else if(sizeof(tData2d) == sizeof(double)) out_type_id = H5T_NATIVE_DOUBLE; else { printf("2dData::writeHDF5: unsuppoted data type\n"); exit(1); } // Create the file and data group hid_t file_id; file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); H5Gcreate1(file_id,"data",0); // Data space dimensions int ndims = 2; hsize_t dims[ndims]; dims[0] = ny; dims[1] = nx; // Write the data hid_t dataspace_id; hid_t dataset_id; dataspace_id = H5Screate_simple(ndims, dims, NULL); dataset_id = H5Dcreate1(file_id, "/data/data", out_type_id, dataspace_id, H5P_DEFAULT); if(H5Dwrite(dataset_id,out_type_id , H5S_ALL, H5S_ALL,H5P_DEFAULT, data)< 0){ printf("2dData::writeHDF5: Error writing data to file\n"); exit(1); } // Close and exit H5Dclose(dataset_id); // Cleanup stale IDs hid_t ids[256]; int n_ids = H5Fget_obj_ids(file_id, H5F_OBJ_ALL, 256, ids); for (long i=0; i<n_ids; i++ ) { hid_t id; H5I_type_t type; id = ids[i]; type = H5Iget_type(id); if ( type == H5I_GROUP ) H5Gclose(id); if ( type == H5I_DATASET ) H5Dclose(id); if ( type == H5I_DATASPACE ) H5Sclose(id); //if ( type == H5I_DATATYPE ) // H5Dclose(id); } H5Fclose(file_id); }
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 }