herr_t H5IMmake_image_8bit( hid_t loc_id, const char *dset_name, hsize_t width, hsize_t height, const unsigned char *buf ) { hsize_t dims[IMAGE8_RANK]; /* check the arguments */ if (dset_name == NULL) return -1; /* Initialize the image dimensions */ dims[0] = height; dims[1] = width; /* Make the dataset */ if ( H5LTmake_dataset( loc_id, dset_name, IMAGE8_RANK, dims, H5T_NATIVE_UCHAR, buf ) < 0) return -1; /* Attach the CLASS attribute */ if ( H5LTset_attribute_string( loc_id, dset_name, "CLASS", IMAGE_CLASS ) < 0) return -1; /* Attach the VERSION attribute */ if ( H5LTset_attribute_string( loc_id, dset_name, "IMAGE_VERSION", IMAGE_VERSION ) < 0) return -1; /* Attach the IMAGE_SUBCLASS attribute */ if ( H5LTset_attribute_string( loc_id, dset_name, "IMAGE_SUBCLASS", "IMAGE_INDEXED" ) < 0) return -1; return 0; }
bool MaskedImage::writeMaskHDF5File(const UString & fileName) const { hid_t fileID = H5Fopen(fileName, H5F_ACC_RDWR, H5P_DEFAULT); if(fileID < 0) { fprintf(stderr, "MaskedImage::writeMaskHDF5File: Could not create file %s\n", (const char *)fileName); return false; } UString dataSetName = "/mask"; hsize_t dimensions[2]; dimensions[0] = (hsize_t)getYSize(); dimensions[1] = (hsize_t)getXSize(); herr_t status = H5LTmake_dataset(fileID, dataSetName, 2, dimensions, H5T_NATIVE_UCHAR, mask.getData()); if((status < 0)) { fprintf(stderr, "MaskedImage::writeMaskHDF5File: Could not make dataset %s in file %s\n", (const char *)dataSetName, (const char *)fileName); return false; } status = H5Fclose(fileID); return true; }
bool MaskedImage::writeTimeHDF5File(const UString & fileName, double inTime) { hid_t fileID = H5Fopen(fileName, H5F_ACC_RDWR, H5P_DEFAULT); if(fileID < 0) { fprintf(stderr, "MaskedImage::writeMaskHDF5File: Could not create file %s\n", (const char *)fileName); return false; } UString dataSetName = "/time"; hsize_t dimensions[1]; dimensions[0] = (hsize_t)1; herr_t status = H5LTmake_dataset(fileID, dataSetName, 1, dimensions, H5T_NATIVE_DOUBLE, &inTime); if((status < 0)) { fprintf(stderr, "MaskedImage::writeMaskHDF5File: Could not make dataset %s in file %s\n", (const char *)dataSetName, (const char *)fileName); return false; } status = H5Fclose(fileID); return true; }
herr_t H5IMmake_palette( hid_t loc_id, const char *pal_name, const hsize_t *pal_dims, const unsigned char *pal_data ) { int has_pal; /* check the arguments */ if (pal_name == NULL) return -1; /* Check if the dataset already exists */ has_pal = H5LTfind_dataset( loc_id, pal_name ); /* It exists. Return */ if ( has_pal == 1 ) return 0; /* Make the palette dataset. */ if ( H5LTmake_dataset( loc_id, pal_name, 2, pal_dims, H5T_NATIVE_UCHAR, pal_data ) < 0 ) return -1; /* Attach the attribute "CLASS" to the >>palette<< dataset*/ if ( H5LTset_attribute_string( loc_id, pal_name, "CLASS", PALETTE_CLASS ) < 0) return -1; /* Attach the attribute "PAL_VERSION" to the >>palette<< dataset*/ if ( H5LTset_attribute_string( loc_id, pal_name, "PAL_VERSION", "1.2" ) < 0) return -1; return 0; }
int_f nh5ltmake_dataset_c (hid_t_f *loc_id, int_f *namelen, _fcd name, int_f *rank, hsize_t_f *dims, hid_t_f *type_id, void *buf) { int ret_value = -1; herr_t ret; hid_t c_loc_id; hid_t c_type_id; char *c_name = NULL; hsize_t *c_dims = NULL; int c_namelen; int i; /* * convert FORTRAN name to C name */ c_namelen = *namelen; c_name = (char *)HD5f2cstring(name, c_namelen); if (c_name == NULL) goto done; c_dims = malloc(sizeof(hsize_t) * (*rank )); if (c_dims == NULL) goto done; /* * transpose dimension arrays because of C-FORTRAN storage order */ for (i = 0; i < *rank ; i++) { c_dims[i] = dims[*rank - i - 1]; } /* * call H5LTmake_dataset function. */ c_loc_id = (hid_t)*loc_id; c_type_id = (hid_t)*type_id; ret = H5LTmake_dataset(c_loc_id, c_name, *rank, c_dims, c_type_id, buf ); if (ret < 0) goto done; ret_value = 0; done: if(c_name!=NULL) free(c_name); if(c_dims!=NULL) free(c_dims); return ret_value; }
herr_t H5IMmake_image_24bit( hid_t loc_id, const char *dset_name, hsize_t width, hsize_t height, const char *interlace, const unsigned char *buf ) { hsize_t dims[IMAGE24_RANK]; /* check the arguments */ if (interlace == NULL) return -1; if (dset_name == NULL) return -1; /* Initialize the image dimensions */ if ( HDstrncmp( interlace, "INTERLACE_PIXEL",15 ) == 0 ) { /* Number of color planes is defined as the third dimension */ dims[0] = height; dims[1] = width; dims[2] = IMAGE24_RANK; } else if ( HDstrncmp( interlace, "INTERLACE_PLANE",15 ) == 0 ) { /* Number of color planes is defined as the first dimension */ dims[0] = IMAGE24_RANK; dims[1] = height; dims[2] = width; } else return -1; /* Make the dataset */ if ( H5LTmake_dataset( loc_id, dset_name, IMAGE24_RANK, dims, H5T_NATIVE_UCHAR, buf ) < 0) return -1; /* Attach the CLASS attribute */ if ( H5LTset_attribute_string( loc_id, dset_name, "CLASS", IMAGE_CLASS ) < 0) return -1; /* Attach the VERSION attribute */ if ( H5LTset_attribute_string( loc_id, dset_name, "IMAGE_VERSION", IMAGE_VERSION ) < 0) return -1; /* Attach the IMAGE_SUBCLASS attribute */ if ( H5LTset_attribute_string( loc_id, dset_name, "IMAGE_SUBCLASS", "IMAGE_TRUECOLOR" ) < 0) return -1; /* Attach the INTERLACE_MODE attribute. This attributes is only for true color images */ if ( H5LTset_attribute_string( loc_id, dset_name, "INTERLACE_MODE", interlace ) < 0) return -1; return 0; }
void hdf5_h5lt_make_dataset(value loc_id_v, value dset_name_v, value type_id_v, value buffer_v) { CAMLparam4(loc_id_v, dset_name_v, type_id_v, buffer_v); struct caml_ba_array *buffer = Caml_ba_array_val(buffer_v); raise_if_fail(H5LTmake_dataset(Hid_val(loc_id_v), String_val(dset_name_v), buffer->num_dims, (const hsize_t*) buffer->dim, Hid_val(type_id_v), buffer->data)); CAMLreturn0; }
/* Save the trace to disk. * * The file name is set by config.file_id so a call to mcmc_set_file() * should be made first. * * Input: * - config: mcmc_confguration * - param_num: parameter number * - param_name: parameter name to be given to the dataset * * Returns: 0 */ int mcmc_save_trace(mcmc_configuration config, int param_num, const char* param_name) { double* trace; trace = mcmc_trace(config, param_num); hsize_t dims[1] = {config.n_iter}; H5LTmake_dataset (config.file_id, param_name, 1, dims, H5T_NATIVE_DOUBLE, trace); return 0; }
void dump_particles_hdf(char *outfile, struct PList * p) { hid_t file_id,group_id; herr_t status; size_t i, j,nread=0; hsize_t dims[2]; //if(try_readfile(outfile)) file_id = H5Fcreate (outfile, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); //always create a new file or overwite existing file // group_id = HDFcreate_group(file_id, "/PartType0"); // status = H5Gclose(group_id); float (* pos)[3],(* vel)[3]; pos=malloc(sizeof(float)*3*p->np); vel=malloc(sizeof(float)*3*p->np); for(i=0;i<p->np;i++) { for(j=0;j<3;j++) { pos[i][j]=(Particles.Pos[p->PIndex[i]][j]-CoM[j])*LUNIT; vel[i][j]=Particles.Vel[p->PIndex[i]][j]-VCoM[j]; } } dims[0]=p->np; dims[1]=3; status = H5LTmake_dataset(file_id,"/x",2,dims,H5T_NATIVE_FLOAT,pos); status = H5LTmake_dataset(file_id,"/v",2,dims,H5T_NATIVE_FLOAT,vel); H5LTset_attribute_float(file_id, "/x", "x0", CoM, 3); H5LTset_attribute_float(file_id, "/v", "v0", VCoM, 3); dims[0]=p->np; dims[1]=1; status = H5LTmake_dataset(file_id,"/Pid",2,dims,H5T_NATIVE_INT,p->PIndex); /* close file */ status = H5Fclose (file_id); printf("Pos[1]: (%g,%g,%g)\n",pos[1][0],pos[1][1],pos[1][2]); free(pos); free(vel); }
/** * Write data into a dataset. * * @param [in] DatasetName * @param [in] DimensionSizes * @param [in] Data * @throw ios::failure */ void THDF5_File::WriteCompleteDataset (const char * DatasetName, const TDimensionSizes & DimensionSizes, const long * Data){ const int rank = 3; const hsize_t dims[]={DimensionSizes.Z, DimensionSizes.Y,DimensionSizes.X}; // write to dataset herr_t status = H5LTmake_dataset(HDF5_FileId,DatasetName,rank,dims, H5T_STD_U64LE, Data); if (status < 0) { char ErrorMessage[256]; sprintf(ErrorMessage,HDF5_ERR_FMT_CouldNotWriteTo,DatasetName); throw ios::failure(ErrorMessage); } }// end of WriteDataset (long)
int main( void ) { hid_t file_id; hsize_t dims[RANK]={2,3}; int data[6]={1,2,3,4,5,6}; herr_t status; /* create a HDF5 file */ file_id = H5Fcreate ("ex_lite1.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); /* create and write an integer type dataset named "dset" */ status = H5LTmake_dataset(file_id,"/dset",RANK,dims,H5T_NATIVE_INT,data); /* close file */ status = H5Fclose (file_id); return 0; }
int main (int argc, char ** argv) { char filename [256]; int rank, size, gidx, i, j, k,l; MPI_Comm comm_dummy = MPI_COMM_WORLD; /* MPI_Comm is defined through adios_read.h */ enum ADIOS_DATATYPES attr_type; void * data = NULL; uint64_t start[] = {0,0,0,0,0,0,0,0,0,0}; uint64_t count[MAX_DIMS], hcount[MAX_DIMS], bytes_read = 0; herr_t h5_err; char h5name[256],aname[256],fname[256]; int dims [MAX_DIMS]; int h5rank[MAX_DIMS]; int h5i, level; hid_t grp_id [GMAX+1], space_id, dataset_id; hid_t memspace_id, dataspace_id, att_id; char ** grp_name; hid_t type_id; hid_t h5_type_id; hsize_t adims; if (argc < 2) { printf("Usage: %s <BP-file> <HDF5-file>\n", argv[0]); return 1; } MPI_Init(&argc, &argv); h5_err = H5Eset_auto(NULL, NULL ); ADIOS_FILE * f = adios_fopen (argv[1], comm_dummy); HDF5_FILE = H5Fcreate(argv[2],H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); /* create the complex types for HDF5 */ complex_real_id = H5Tcreate (H5T_COMPOUND, sizeof (complex_real_t)); H5Tinsert (complex_real_id, "real", HOFFSET(complex_real_t,re), H5T_NATIVE_FLOAT); H5Tinsert (complex_real_id, "imaginary", HOFFSET(complex_real_t,im), H5T_NATIVE_FLOAT); complex_double_id = H5Tcreate (H5T_COMPOUND, sizeof (complex_double_t)); H5Tinsert (complex_double_id, "real", HOFFSET(complex_double_t,re), H5T_NATIVE_DOUBLE); H5Tinsert (complex_double_id, "imaginary", HOFFSET(complex_double_t,im), H5T_NATIVE_DOUBLE); if (f == NULL) { if (DEBUG) printf ("%s\n", adios_errmsg()); return -1; } /* For all groups */ for (gidx = 0; gidx < f->groups_count; gidx++) { if (DEBUG) printf("Group %s:\n", f->group_namelist[gidx]); ADIOS_GROUP * g = adios_gopen (f, f->group_namelist[gidx]); if (g == NULL) { if (DEBUG) printf ("%s\n", adios_errmsg()); return -1; } /* First create all of the groups */ grp_id [0] = HDF5_FILE; for (i = 0; i < g->vars_count; i++) { ADIOS_VARINFO * v = adios_inq_var_byid (g, i); strcpy(h5name,g->var_namelist[i]); grp_name = bp_dirparser (h5name, &level); for (j = 0; j < level-1; j++) { grp_id [j + 1] = H5Gopen (grp_id [j], grp_name [j]); if (grp_id [j + 1] < 0) { grp_id [j + 1] = H5Gcreate (grp_id [j], grp_name [j], 0); } } for (j=1; j<level; j++) { H5Gclose(grp_id[j]); } } /* Now we can write data into these scalars */ /* For all variables */ if (DEBUG) printf(" Variables=%d:\n", g->vars_count); for (i = 0; i < g->vars_count; i++) { ADIOS_VARINFO * v = adios_inq_var_byid (g, i); uint64_t total_size = adios_type_size (v->type, v->value); for (j = 0; j < v->ndim; j++) total_size *= v->dims[j]; strcpy(h5name,g->var_namelist[i]); if (DEBUG) printf(" %-9s %s", adios_type_to_string(v->type), g->var_namelist[i]); h5_err = bp_getH5TypeId (v->type, &h5_type_id); if (v->type==adios_string) H5Tset_size(h5_type_id,strlen(v->value)); if (v->ndim == 0) { /* Scalars do not need to be read in, we get it from the metadata when using adios_inq_var */ if (DEBUG) printf(" = %s\n", value_to_string(v->type, v->value, 0)); // add the hdf5 dataset, these are scalars for (h5i = 0;h5i<MAX_DIMS;h5i++) count[0] = 0; count[0] = 1; // we are writing just 1 element, RANK=1 h5_err = bp_getH5TypeId (v->type, &h5_type_id); H5LTmake_dataset(HDF5_FILE,h5name,1,count,h5_type_id,v->value); } else { h5_err = readVar(g, v, h5name); } adios_free_varinfo (v); } /* variables */ /* For all attributes */ if (DEBUG) printf(" Attributes=%d:\n", g->attrs_count); for (i = 0; i < g->attrs_count; i++) { enum ADIOS_DATATYPES atype; int asize; void *adata; adios_get_attr_byid (g, i, &atype, &asize, &adata); grp_name = bp_dirparser (g->attr_namelist[i], &level); strcpy(aname,grp_name[level-1]); // the name of the attribute is the last in the array // we then need to concat the rest together strcpy(fname,"/"); for (j=0;j<level-1;j++) { strcat(fname,grp_name[j]); } h5_err = bp_getH5TypeId (atype, &h5_type_id); // let's create the attribute adims = 1; if (atype==adios_string) H5Tset_size(h5_type_id,strlen(adata)); space_id = H5Screate(H5S_SCALAR); // just a scalar att_id = H5Acreate(HDF5_FILE, g->attr_namelist[i], h5_type_id, space_id,H5P_DEFAULT); h5_err = H5Awrite(att_id, h5_type_id, adata); h5_err = H5Aclose(att_id); h5_err = H5Sclose(space_id); if (DEBUG) printf(" %-9s %s = %s\n", adios_type_to_string(atype), g->attr_namelist[i], value_to_string(atype, adata, 0)); free(adata); } /* attributes */ adios_gclose (g); } /* groups */ adios_fclose (f); h5_err = H5Fclose(HDF5_FILE); MPI_Finalize(); return 0; }
bool stfio::exportHDF5File(const std::string& fName, const Recording& WData, ProgressInfo& progDlg) { hid_t file_id = H5Fcreate(fName.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); const int NRECORDS = 1; const int NFIELDS = 3; /* Calculate the size and the offsets of our struct members in memory */ size_t rt_offset[NFIELDS] = { HOFFSET( rt, channels ), HOFFSET( rt, date ), HOFFSET( rt, time )}; /* Define an array of root tables */ rt p_data; p_data.channels = WData.size(); struct tm t = WData.GetDateTime(); std::size_t date_length = snprintf(p_data.date, DATELEN, "%04i-%02i-%02i", t.tm_year+1900, t.tm_mon+1, t.tm_mday); std::size_t time_length = snprintf(p_data.time, TIMELEN, "%02i:%02i:%02i", t.tm_hour, t.tm_min, t.tm_sec); // ensure that an undefine string is set to "\0", and that the terminating \0 is counted in string length p_data.date[date_length++] = 0; p_data.time[time_length++] = 0; /* Define field information */ const char *field_names[NFIELDS] = { "channels", "date", "time" }; hid_t field_type[NFIELDS]; /* Initialize the field field_type */ hid_t string_type1 = H5Tcopy( H5T_C_S1 ); hid_t string_type2 = H5Tcopy( H5T_C_S1 ); H5Tset_size( string_type1, date_length); H5Tset_size( string_type2, time_length); field_type[0] = H5T_NATIVE_INT; field_type[1] = string_type1; field_type[2] = string_type2; std::ostringstream desc; desc << "Description of " << fName; herr_t status = H5TBmake_table( desc.str().c_str(), file_id, "description", (hsize_t)NFIELDS, (hsize_t)NRECORDS, sizeof(rt), field_names, rt_offset, field_type, 10, NULL, 0, &p_data ); if (status < 0) { std::string errorMsg("Exception while writing description in stfio::exportHDF5File"); H5Fclose(file_id); H5close(); throw std::runtime_error(errorMsg); } hid_t comment_group = H5Gcreate2( file_id,"/comment", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); /* File comment. */ std::string description(WData.GetFileDescription()); if (description.length() <= 0) { description = "No description"; } status = H5LTmake_dataset_string(file_id, "/comment/description", description.c_str()); if (status < 0) { std::string errorMsg("Exception while writing description in stfio::exportHDF5File"); H5Fclose(file_id); H5close(); throw std::runtime_error(errorMsg); } std::string comment(WData.GetComment()); if (comment.length() <= 0) { comment = "No comment"; } status = H5LTmake_dataset_string(file_id, "/comment/comment", comment.c_str()); if (status < 0) { std::string errorMsg("Exception while writing comment in stfio::exportHDF5File"); H5Fclose(file_id); H5close(); throw std::runtime_error(errorMsg); } H5Gclose(comment_group); std::vector<std::string> channel_name(WData.size()); hid_t channels_group = H5Gcreate2( file_id,"/channels", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); for ( std::size_t n_c=0; n_c < WData.size(); ++n_c) { /* Channel descriptions. */ std::ostringstream ossname; ossname << WData[n_c].GetChannelName(); if ( ossname.str() == "" ) { ossname << "ch" << (n_c); } channel_name[n_c] = ossname.str(); hsize_t dimsc[1] = { 1 }; hid_t string_typec = H5Tcopy( H5T_C_S1 ); std::size_t cn_length = channel_name[n_c].length(); if (cn_length <= 0) cn_length = 1; H5Tset_size( string_typec, cn_length ); std::vector<char> datac(channel_name[n_c].length()); std::copy(channel_name[n_c].begin(),channel_name[n_c].end(), datac.begin()); std::ostringstream desc_path; desc_path << "/channels/ch" << (n_c); status = H5LTmake_dataset(file_id, desc_path.str().c_str(), 1, dimsc, string_typec, &datac[0]); if (status < 0) { std::string errorMsg("Exception while writing channel name in stfio::exportHDF5File"); H5Fclose(file_id); H5close(); throw std::runtime_error(errorMsg); } std::ostringstream channel_path; channel_path << "/" << channel_name[n_c]; hid_t channel_group = H5Gcreate2( file_id, channel_path.str().c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); if (channel_group < 0) { std::ostringstream errorMsg; errorMsg << "Exception while creating channel group for " << channel_path.str().c_str(); H5Fclose(file_id); H5close(); throw std::runtime_error(errorMsg.str()); } /* Calculate the size and the offsets of our struct members in memory */ size_t ct_size = sizeof( ct ); size_t ct_offset[1] = { HOFFSET( rt, channels ) }; /* Define an array of channel tables */ ct c_data = { (int)WData[n_c].size() }; /* Define field information */ const char *cfield_names[1] = { "n_sections" }; hid_t cfield_type[1] = {H5T_NATIVE_INT}; std::ostringstream c_desc; c_desc << "Description of channel " << n_c; status = H5TBmake_table( c_desc.str().c_str(), channel_group, "description", (hsize_t)1, (hsize_t)1, ct_size, cfield_names, ct_offset, cfield_type, 10, NULL, 0, &c_data ); if (status < 0) { std::string errorMsg("Exception while writing channel description in stfio::exportHDF5File"); H5Fclose(file_id); H5close(); throw std::runtime_error(errorMsg); } int max_log10 = 0; if (WData[n_c].size() > 1) { max_log10 = int(log10((double)WData[n_c].size()-1.0)); } for (std::size_t n_s=0; n_s < WData[n_c].size(); ++n_s) { int progbar = // Channel contribution: (int)(((double)n_c/(double)WData.size())*100.0+ // Section contribution: (double)(n_s)/(double)WData[n_c].size()*(100.0/WData.size())); std::ostringstream progStr; progStr << "Writing channel #" << n_c + 1 << " of " << WData.size() << ", Section #" << n_s << " of " << WData[n_c].size(); progDlg.Update(progbar, progStr.str()); // construct a number with leading zeros: int n10 = 0; if (n_s > 0) { n10 = int(log10((double)n_s)); } std::ostringstream strZero; strZero << ""; for (int n_z=n10; n_z < max_log10; ++n_z) { strZero << "0"; } // construct a section name: std::ostringstream section_name; section_name << WData[n_c][n_s].GetSectionDescription(); if ( section_name.str() == "" ) { section_name << "sec" << n_s; } // create a child group in the channel: std::ostringstream section_path; section_path << channel_path.str() << "/" << "section_" << strZero.str() << n_s; hid_t section_group = H5Gcreate2( file_id, section_path.str().c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); // add data and description, store as 32 bit little endian independent of machine: hsize_t dims[1] = { WData[n_c][n_s].size() }; std::ostringstream data_path; data_path << section_path.str() << "/data"; Vector_float data_cp(WData[n_c][n_s].get().size()); /* 32 bit */ for (std::size_t n_cp = 0; n_cp < WData[n_c][n_s].get().size(); ++n_cp) { data_cp[n_cp] = float(WData[n_c][n_s][n_cp]); } status = H5LTmake_dataset(file_id, data_path.str().c_str(), 1, dims, H5T_IEEE_F32LE, &data_cp[0]); if (status < 0) { std::string errorMsg("Exception while writing data in stfio::exportHDF5File"); H5Fclose(file_id); H5close(); throw std::runtime_error(errorMsg); } const int NSRECORDS = 1; const int NSFIELDS = 3; /* Calculate the size and the offsets of our struct members in memory */ size_t st_size = sizeof( st ); size_t st_offset[NSFIELDS] = { HOFFSET( st, dt ), HOFFSET( st, xunits ), HOFFSET( st, yunits )}; /* Define an array of root tables */ st s_data; s_data.dt = WData.GetXScale(); if (WData.GetXUnits().length() < UNITLEN) strcpy( s_data.xunits, WData.GetXUnits().c_str() ); if (WData[n_c].GetYUnits().length() < UNITLEN) strcpy( s_data.yunits, WData[n_c].GetYUnits().c_str() ); /* Define field information */ const char *sfield_names[NSFIELDS] = { "dt", "xunits", "yunits" }; hid_t sfield_type[NSFIELDS]; /* Initialize the field field_type */ hid_t string_type4 = H5Tcopy( H5T_C_S1 ); hid_t string_type5 = H5Tcopy( H5T_C_S1 ); H5Tset_size( string_type4, 2); std::size_t yu_length = WData[n_c].GetYUnits().length(); if (yu_length <= 0) yu_length = 1; H5Tset_size( string_type5, yu_length ); sfield_type[0] = H5T_NATIVE_DOUBLE; sfield_type[1] = string_type4; sfield_type[2] = string_type5; std::ostringstream sdesc; sdesc << "Description of " << section_name.str(); status = H5TBmake_table( sdesc.str().c_str(), section_group, "description", (hsize_t)NSFIELDS, (hsize_t)NSRECORDS, st_size, sfield_names, st_offset, sfield_type, 10, NULL, 0, &s_data ); if (status < 0) { std::string errorMsg("Exception while writing section description in stfio::exportHDF5File"); H5Fclose(file_id); H5close(); throw std::runtime_error(errorMsg); } H5Gclose(section_group); } H5Gclose(channel_group); } H5Gclose(channels_group); /* Terminate access to the file. */ status = H5Fclose(file_id); if (status < 0) { std::string errorMsg("Exception while closing file in stfio::exportHDF5File"); throw std::runtime_error(errorMsg); } /* Release all hdf5 resources */ status = H5close(); if (status < 0) { std::string errorMsg("Exception while closing file in stfio::exportHDF5File"); throw std::runtime_error(errorMsg); } return (status >= 0); }
/* ------- begin -------------------------- init_aux_new.c -- --- */ void init_aux_new(void) { /* Creates the HDF5 file for the auxiliary data */ const char routineName[] = "init_aux_new"; unsigned int *tmp; double *tmp_double; int i; hid_t plist, ncid, file_dspace, ncid_atom, ncid_mol; hid_t id_x, id_y, id_z, id_n, id_tmp; hsize_t dims[4]; char group_name[ARR_STRLEN]; Atom *atom; Molecule *molecule; /* Create the file */ if (( plist = H5Pcreate(H5P_FILE_ACCESS) ) < 0) HERR(routineName); if (( H5Pset_fapl_mpio(plist, mpi.comm, mpi.info) ) < 0) HERR(routineName); if (( ncid = H5Fcreate(AUX_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, plist) ) < 0) HERR(routineName); if (( H5Pclose(plist) ) < 0) HERR(routineName); /* --- Definitions for the root group --- */ /* dimensions as attributes */ if (( H5LTset_attribute_int(ncid, "/", "nx", &mpi.nx, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid, "/", "ny", &mpi.ny, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid, "/", "nz", (int *) &infile.nz, 1 )) < 0) HERR(routineName); /* attributes */ if (( H5LTset_attribute_string(ncid, "/", "atmosID", atmos.ID)) < 0) HERR(routineName); if (( H5LTset_attribute_string(ncid, "/", "rev_id", mpi.rev_id) ) < 0) HERR(routineName); /* Create arrays for multiple-atom/molecule output */ io.aux_atom_ncid = (hid_t *) malloc(atmos.Nactiveatom * sizeof(hid_t)); io.aux_mol_ncid = (hid_t *) malloc(atmos.Nactivemol * sizeof(hid_t)); if (input.p15d_wpop) { io.aux_atom_pop = (hid_t *) malloc(atmos.Nactiveatom * sizeof(hid_t)); io.aux_atom_poplte = (hid_t *) malloc(atmos.Nactiveatom * sizeof(hid_t)); io.aux_mol_pop = (hid_t *) malloc(atmos.Nactivemol * sizeof(hid_t)); io.aux_mol_poplte = (hid_t *) malloc(atmos.Nactivemol * sizeof(hid_t)); } if (input.p15d_wrates) { io.aux_atom_RijL = (hid_t *) malloc(atmos.Nactiveatom * sizeof(hid_t)); io.aux_atom_RjiL = (hid_t *) malloc(atmos.Nactiveatom * sizeof(hid_t)); io.aux_atom_RijC = (hid_t *) malloc(atmos.Nactiveatom * sizeof(hid_t)); io.aux_atom_RjiC = (hid_t *) malloc(atmos.Nactiveatom * sizeof(hid_t)); } /* Fill value */ if (( plist = H5Pcreate(H5P_DATASET_CREATE) ) < 0) HERR(routineName); if (( H5Pset_fill_value(plist, H5T_NATIVE_FLOAT, &FILLVALUE) ) < 0) HERR(routineName); if (( H5Pset_alloc_time(plist, H5D_ALLOC_TIME_EARLY) ) < 0) HERR(routineName); if (( H5Pset_fill_time(plist, H5D_FILL_TIME_ALLOC) ) < 0) HERR(routineName); /* --- Group loop over active ATOMS --- */ for (i=0; i < atmos.Nactiveatom; i++) { atom = atmos.activeatoms[i]; /* Get group name */ sprintf(group_name, (atom->ID[1] == ' ') ? "atom_%.1s" : "atom_%.2s", atom->ID); if (( ncid_atom = H5Gcreate(ncid, group_name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) ) < 0) HERR(routineName); io.aux_atom_ncid[i] = ncid_atom; /* --- dimensions as attributes --- */ if (( H5LTset_attribute_int(ncid_atom, ".", "nlevel", &atom->Nlevel, 1)) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_atom, ".", "nline", &atom->Nline, 1)) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_atom, ".", "ncontinuum", &atom->Ncont, 1)) < 0) HERR(routineName); /* --- dimension datasets --- */ dims[0] = mpi.nx; if (( H5LTmake_dataset(ncid_atom, X_NAME, 1, dims, H5T_NATIVE_DOUBLE, geometry.xscale) ) < 0) HERR(routineName); if (( id_x = H5Dopen2(ncid_atom, X_NAME, H5P_DEFAULT)) < 0) HERR(routineName); dims[0] = mpi.ny; if (( H5LTmake_dataset(ncid_atom, Y_NAME, 1, dims, H5T_NATIVE_DOUBLE, geometry.yscale) ) < 0) HERR(routineName); if (( id_y = H5Dopen2(ncid_atom, Y_NAME, H5P_DEFAULT)) < 0) HERR(routineName); dims[0] = infile.nz; tmp_double = (double *) calloc(infile.nz , sizeof(double)); if (( H5LTmake_dataset(ncid_atom, ZOUT_NAME, 1, dims, H5T_NATIVE_DOUBLE, tmp_double) ) < 0) HERR(routineName); free(tmp_double); if (( id_z = H5Dopen2(ncid_atom, ZOUT_NAME, H5P_DEFAULT)) < 0) HERR(routineName); dims[0] = atom->Nlevel; tmp = (unsigned int *) calloc(atom->Nlevel , sizeof(unsigned int)); if (( H5LTmake_dataset(ncid_atom, LEVEL_NAME, 1, dims, H5T_NATIVE_UINT, tmp) ) < 0) HERR(routineName); free(tmp); dims[0] = atom->Nline; tmp = (unsigned int *) calloc(atom->Nline , sizeof(unsigned int)); if (( H5LTmake_dataset(ncid_atom, LINE_NAME, 1, dims, H5T_NATIVE_UINT, tmp) ) < 0) HERR(routineName); free(tmp); if (atom->Ncont > 0) { dims[0] = atom->Ncont; tmp = (unsigned int *) calloc(atom->Ncont , sizeof(unsigned int)); if (( H5LTmake_dataset(ncid_atom, CONT_NAME, 1, dims, H5T_NATIVE_UINT, tmp) ) < 0) HERR(routineName); free(tmp); } /* For compatibility with netCDF readers, only use dataset as dimension */ if (( H5LTset_attribute_string(ncid_atom, ZOUT_NAME, "NAME", NETCDF_COMPAT) ) < 0) HERR(routineName); if (( H5LTset_attribute_string(ncid_atom, LEVEL_NAME, "NAME", NETCDF_COMPAT) ) < 0) HERR(routineName); if (( H5LTset_attribute_string(ncid_atom, LINE_NAME, "NAME", NETCDF_COMPAT) ) < 0) HERR(routineName); if (atom->Ncont > 0) { if (( H5LTset_attribute_string(ncid_atom, CONT_NAME, "NAME", NETCDF_COMPAT) ) < 0) HERR(routineName); } /* --- variables --- */ dims[0] = atom->Nlevel; dims[1] = mpi.nx; dims[2] = mpi.ny; dims[3] = infile.nz; /* Populations */ if (input.p15d_wpop) { if (( file_dspace = H5Screate_simple(4, dims, NULL) ) < 0) HERR(routineName); if (( id_n = H5Dopen2(ncid_atom, LEVEL_NAME, H5P_DEFAULT)) < 0) HERR(routineName); if (atom->n != NULL) { if (( id_tmp = H5Dcreate(ncid_atom, POP_NAME, H5T_NATIVE_FLOAT, file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_n, 0)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_x, 1)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_y, 2)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_z, 3)) < 0) HERR(routineName); if (( H5LTset_attribute_float(ncid_atom, POP_NAME, "_FillValue", &FILLVALUE, 1) ) < 0) HERR(routineName); io.aux_atom_pop[i] = id_tmp; } if (atom->nstar != NULL) { if (( id_tmp = H5Dcreate(ncid_atom, POPLTE_NAME, H5T_NATIVE_FLOAT, file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_n, 0)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_x, 1)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_y, 2)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_z, 3)) < 0) HERR(routineName); if (( H5LTset_attribute_float(ncid_atom, POPLTE_NAME, "_FillValue", &FILLVALUE, 1) ) < 0) HERR(routineName); io.aux_atom_poplte[i] = id_tmp; } if (( H5Dclose(id_n) ) < 0) HERR(routineName); if (( H5Sclose(file_dspace) ) < 0) HERR(routineName); } if (input.p15d_wrates) { /* Radiative rates */ dims[0] = atom->Nline; dims[1] = mpi.nx; dims[2] = mpi.ny; dims[3] = infile.nz; if (( file_dspace = H5Screate_simple(4, dims, NULL) ) < 0) HERR(routineName); if (( id_n = H5Dopen2(ncid_atom, LINE_NAME, H5P_DEFAULT)) < 0) HERR(routineName); if (( id_tmp = H5Dcreate(ncid_atom, RIJ_L_NAME, H5T_NATIVE_FLOAT, file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_n, 0)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_x, 1)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_y, 2)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_z, 3)) < 0) HERR(routineName); if (( H5LTset_attribute_float(ncid_atom, RIJ_L_NAME, "_FillValue", &FILLVALUE, 1) ) < 0) HERR(routineName); io.aux_atom_RijL[i] = id_tmp; if (( id_tmp = H5Dcreate(ncid_atom, RJI_L_NAME, H5T_NATIVE_FLOAT, file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_n, 0)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_x, 1)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_y, 2)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_z, 3)) < 0) HERR(routineName); if (( H5LTset_attribute_float(ncid_atom, RJI_L_NAME, "_FillValue", &FILLVALUE, 1) ) < 0) HERR(routineName); io.aux_atom_RjiL[i] = id_tmp; if (( H5Dclose(id_n) ) < 0) HERR(routineName); if (( H5Sclose(file_dspace) ) < 0) HERR(routineName); if (atom->Ncont > 0) { dims[0] = atom->Ncont; if (( file_dspace = H5Screate_simple(4, dims, NULL) ) < 0) HERR(routineName); if (( id_n = H5Dopen2(ncid_atom, CONT_NAME, H5P_DEFAULT)) < 0) HERR(routineName); if (( id_tmp = H5Dcreate(ncid_atom, RIJ_C_NAME, H5T_NATIVE_FLOAT, file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_n, 0)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_x, 1)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_y, 2)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_z, 3)) < 0) HERR(routineName); if (( H5LTset_attribute_float(ncid_atom, RIJ_C_NAME, "_FillValue", &FILLVALUE, 1) ) < 0) HERR(routineName); io.aux_atom_RijC[i] = id_tmp; if (( id_tmp = H5Dcreate(ncid_atom, RJI_C_NAME, H5T_NATIVE_FLOAT, file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_n, 0)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_x, 1)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_y, 2)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_z, 3)) < 0) HERR(routineName); if (( H5LTset_attribute_float(ncid_atom, RJI_C_NAME, "_FillValue", &FILLVALUE, 1) ) < 0) HERR(routineName); io.aux_atom_RjiC[i] = id_tmp; if (( H5Dclose(id_n) ) < 0) HERR(routineName); if (( H5Sclose(file_dspace) ) < 0) HERR(routineName); } } if (( H5Dclose(id_x) ) < 0) HERR(routineName); if (( H5Dclose(id_y) ) < 0) HERR(routineName); if (( H5Dclose(id_z) ) < 0) HERR(routineName); } /* end active ATOMS loop */ /* --- Group loop over active MOLECULES --- */ for (i=0; i < atmos.Nactivemol; i++) { molecule = atmos.activemols[i]; /* Get group name */ sprintf( group_name, "molecule_%s", molecule->ID); if (( ncid_mol = H5Gcreate(ncid, group_name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) ) < 0) HERR(routineName); io.aux_mol_ncid[i] = ncid_mol; /* --- dimensions as attributes --- */ if (( H5LTset_attribute_int(ncid_mol, ".", "nlevel_vibr", &molecule->Nv, 1)) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_mol, ".", "nline_molecule", &molecule->Nrt, 1)) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_mol, ".", "nJ", &molecule->NJ, 1)) < 0) HERR(routineName); /* --- dimension datasets --- */ dims[0] = mpi.nx; if (( H5LTmake_dataset(ncid_mol, X_NAME, 1, dims, H5T_NATIVE_DOUBLE, geometry.xscale) ) < 0) HERR(routineName); if (( id_x = H5Dopen2(ncid_mol, X_NAME, H5P_DEFAULT)) < 0) HERR(routineName); dims[0] = mpi.ny; if (( H5LTmake_dataset(ncid_mol, Y_NAME, 1, dims, H5T_NATIVE_DOUBLE, geometry.yscale) ) < 0) HERR(routineName); if (( id_y = H5Dopen2(ncid_mol, Y_NAME, H5P_DEFAULT)) < 0) HERR(routineName); dims[0] = infile.nz; tmp_double = (double *) calloc(infile.nz , sizeof(double)); if (( H5LTmake_dataset(ncid_mol, ZOUT_NAME, 1, dims, H5T_NATIVE_DOUBLE, tmp_double) ) < 0) HERR(routineName); free(tmp_double); if (( id_z = H5Dopen2(ncid_mol, ZOUT_NAME, H5P_DEFAULT)) < 0) HERR(routineName); dims[0] = molecule->Nv; tmp = (unsigned int *) calloc(molecule->Nv, sizeof(unsigned int)); if (( H5LTmake_dataset(ncid_mol, VLEVEL_NAME, 1, dims, H5T_NATIVE_UINT, tmp) ) < 0) HERR(routineName); free(tmp); dims[0] = molecule->Nrt; tmp = (unsigned int *) calloc(molecule->Nrt, sizeof(unsigned int)); if (( H5LTmake_dataset(ncid_mol, VLINE_NAME, 1, dims, H5T_NATIVE_UINT, tmp) ) < 0) HERR(routineName); free(tmp); dims[0] = molecule->NJ; tmp = (unsigned int *) calloc(molecule->NJ, sizeof(unsigned int)); if (( H5LTmake_dataset(ncid_mol, NJ_NAME, 1, dims, H5T_NATIVE_UINT, tmp) ) < 0) HERR(routineName); free(tmp); /* For compatibility with netCDF readers, only use dataset as dimension */ if (( H5LTset_attribute_string(ncid_mol, ZOUT_NAME, "NAME", NETCDF_COMPAT) ) < 0) HERR(routineName); if (( H5LTset_attribute_string(ncid_mol, VLEVEL_NAME, "NAME", NETCDF_COMPAT) ) < 0) HERR(routineName); if (( H5LTset_attribute_string(ncid_mol, VLINE_NAME, "NAME", NETCDF_COMPAT) ) < 0) HERR(routineName); if (( H5LTset_attribute_string(ncid_mol, NJ_NAME, "NAME", NETCDF_COMPAT) ) < 0) HERR(routineName); /* --- variables --- */ dims[0] = molecule->Nv; dims[1] = mpi.nx; dims[2] = mpi.ny; dims[3] = infile.nz; /* Populations */ if (input.p15d_wpop) { if (( file_dspace = H5Screate_simple(4, dims, NULL) ) < 0) HERR(routineName); if (( id_n = H5Dopen2(ncid_mol, VLEVEL_NAME, H5P_DEFAULT)) < 0) HERR(routineName); if (molecule->nv != NULL) { if (( id_tmp = H5Dcreate(ncid_mol, POP_NAME, H5T_NATIVE_FLOAT, file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_n, 0)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_x, 1)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_y, 2)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_z, 3)) < 0) HERR(routineName); io.aux_mol_pop[i] = id_tmp; } if (molecule->nvstar != NULL) { if (( id_tmp = H5Dcreate(ncid_mol, POPLTE_NAME, H5T_NATIVE_FLOAT, file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_n, 0)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_x, 1)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_y, 2)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_z, 3)) < 0) HERR(routineName); io.aux_mol_poplte[i] = id_tmp; } if (( H5Dclose(id_n) ) < 0) HERR(routineName); if (( H5Sclose(file_dspace) ) < 0) HERR(routineName); // TODO: molecule->Ediss, molecule->Tmin, molecule->Tmax } if (( H5Dclose(id_x) ) < 0) HERR(routineName); if (( H5Dclose(id_y) ) < 0) HERR(routineName); if (( H5Dclose(id_z) ) < 0) HERR(routineName); } /* end active MOLECULES loop */ io.aux_ncid = ncid; /* Copy stuff to the IO data struct */ if (( H5Pclose(plist) ) < 0) HERR(routineName); /* Free hdf5 resources */ /* Flush ensures file is created in case of crash */ if (( H5Fflush(ncid, H5F_SCOPE_LOCAL) ) < 0) HERR(routineName); return; }
/* ------- begin -------------------------- init_hdf5_indata.c --- */ void init_hdf5_indata_new(void) /* Creates the netCDF file for the input data */ { const char routineName[] = "init_hdf5_indata_new"; int i, PRD_angle_dep; double *eweight, *eabund, *x, *y; /* This value is harcoded for efficiency. Maximum number of iterations ever needed */ int NMaxIter = 1500; hid_t plist, ncid, file_dspace, ncid_input, ncid_atmos, ncid_mpi; hsize_t dims[4]; bool_t XRD; char startJ[MAX_LINE_SIZE], StokesMode[MAX_LINE_SIZE], angleSet[MAX_LINE_SIZE]; /* Create the file */ if (( plist = H5Pcreate(H5P_FILE_ACCESS )) < 0) HERR(routineName); if (( H5Pset_fapl_mpio(plist, mpi.comm, mpi.info) ) < 0) HERR(routineName); if (( ncid = H5Fcreate(INPUTDATA_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, plist) ) < 0) HERR(routineName); if (( H5Pclose(plist) ) < 0) HERR(routineName); /* Create groups */ if (( ncid_input = H5Gcreate(ncid, "/input", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) ) < 0) HERR(routineName); if (( ncid_atmos = H5Gcreate(ncid, "/atmos", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) ) < 0) HERR(routineName); if (( ncid_mpi = H5Gcreate(ncid, "/mpi", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) ) < 0) HERR(routineName); /* --- Definitions for the root group --- */ /* dimensions as attributes */ if (( H5LTset_attribute_int(ncid, "/", "nx", &mpi.nx, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid, "/", "ny", &mpi.ny, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid, "/", "nz", (int *) &infile.nz, 1 )) < 0) HERR(routineName); /* attributes */ if (( H5LTset_attribute_string(ncid, "/", "atmosID", atmos.ID)) < 0) HERR(routineName); if (( H5LTset_attribute_string(ncid, "/", "rev_id", mpi.rev_id) ) < 0) HERR(routineName); /* --- Definitions for the INPUT group --- */ /* attributes */ if ( atmos.NPRDactive > 0) PRD_angle_dep = input.PRD_angle_dep; else PRD_angle_dep=0; XRD = (input.XRD && atmos.NPRDactive > 0); if (( H5LTset_attribute_uchar(ncid_input, ".", "Magneto_optical", (unsigned char *) &input.magneto_optical, 1)) < 0) HERR(routineName); if (( H5LTset_attribute_uchar(ncid_input, ".", "PRD_angle_dep", (unsigned char *) &PRD_angle_dep, 1)) < 0) HERR(routineName); if (( H5LTset_attribute_uchar(ncid_input, ".", "XRD", (unsigned char *) &XRD, 1)) < 0) HERR(routineName); if (( H5LTset_attribute_uchar(ncid_input, ".", "Background_polarization", (unsigned char *) &input.backgr_pol, 1)) < 0) HERR(routineName); switch (input.startJ) { case UNKNOWN: strcpy(startJ, "Unknown"); break; case LTE_POPULATIONS: strcpy(startJ, "LTE_POPULATIONS"); break; case ZERO_RADIATION: strcpy(startJ, "ZERO_RADIATION"); break; case OLD_POPULATIONS: strcpy(startJ, "OLD_POPULATIONS"); break; case ESCAPE_PROBABILITY: strcpy(startJ, "ESCAPE_PROBABILITY"); break; case NEW_J: strcpy(startJ, "NEW_J"); break; case OLD_J: strcpy(startJ, "OLD_J"); break; } if (( H5LTset_attribute_string(ncid_input, ".", "Start_J", startJ)) < 0) HERR(routineName); switch (input.StokesMode) { case NO_STOKES: strcpy(StokesMode, "NO_STOKES"); break; case FIELD_FREE: strcpy(StokesMode, "FIELD_FREE"); break; case POLARIZATION_FREE: strcpy(StokesMode, "POLARIZATION_FREE"); break; case FULL_STOKES: strcpy(StokesMode, "FULL_STOKES"); break; } if (( H5LTset_attribute_string(ncid_input, ".", "Stokes_mode", StokesMode) ) < 0) HERR(routineName); switch (atmos.angleSet.set) { case SET_VERTICAL: strcpy(angleSet, "SET_VERTICAL"); break; case SET_GL: strcpy(angleSet, "SET_GL"); break; case SET_A2: strcpy(angleSet, "SET_A2"); break; case SET_A4: strcpy(angleSet, "SET_A4"); break; case SET_A6: strcpy(angleSet, "SET_A6"); break; case SET_A8: strcpy(angleSet, "SET_A8"); break; case SET_B4: strcpy(angleSet, "SET_B4"); break; case SET_B6: strcpy(angleSet, "SET_B6"); break; case SET_B8: strcpy(angleSet, "SET_B8"); break; case NO_SET: strcpy(angleSet, "NO_SET"); break; } if (( H5LTset_attribute_string(ncid_input, ".", "Angle_set", angleSet) ) < 0) HERR(routineName); if (( H5LTset_attribute_string(ncid_input, ".", "Atmos_file", input.atmos_input) ) < 0) HERR(routineName); if (( H5LTset_attribute_string(ncid_input, ".", "Abundances_file", input.abund_input) ) < 0) HERR(routineName); if (( H5LTset_attribute_string(ncid_input, ".", "Kurucz_PF_data", input.pfData) ) < 0) HERR(routineName); if (( H5LTset_attribute_double(ncid_input, ".", "Iteration_limit", &input.iterLimit, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_double(ncid_input, ".", "PRD_Iteration_limit", &input.PRDiterLimit, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_input, ".", "N_max_iter", &input.NmaxIter, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_input, ".", "Ng_delay", &input.Ngdelay, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_input, ".", "Ng_order", &input.Ngorder, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_input, ".", "Ng_period", &input.Ngperiod, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_input, ".", "PRD_N_max_iter", &input.PRD_NmaxIter, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_input, ".", "PRD_Ng_delay", &input.PRD_Ngdelay, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_input, ".", "PRD_Ng_order", &input.PRD_Ngorder, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_input, ".", "PRD_Ng_period", &input.PRD_Ngperiod, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_double(ncid_input, ".", "Metallicity", &input.metallicity, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_double(ncid_input, ".", "Lambda_reference", &atmos.lambda_ref, 1) ) < 0) HERR(routineName); /* --- Definitions for the ATMOS group --- */ /* dimensions */ if (( H5LTset_attribute_int(ncid_atmos, ".", "nhydr", &atmos.H->Nlevel, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_atmos, ".", "nelements", &atmos.Nelem, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_atmos, ".", "nrays", &geometry.Nrays, 1) ) < 0) HERR(routineName); /* variables*/ dims[0] = mpi.nx; dims[1] = mpi.ny; dims[2] = infile.nz; if (( file_dspace = H5Screate_simple(3, dims, NULL) ) < 0) HERR(routineName); if (( plist = H5Pcreate(H5P_DATASET_CREATE) ) < 0) HERR(routineName); if (( H5Pset_fill_value(plist, H5T_NATIVE_FLOAT, &FILLVALUE) ) < 0) HERR(routineName); if (( H5Pset_alloc_time(plist, H5D_ALLOC_TIME_EARLY) ) < 0) HERR(routineName); if (( H5Pset_fill_time(plist, H5D_FILL_TIME_ALLOC) ) < 0) HERR(routineName); if (( io.in_atmos_T = H5Dcreate(ncid_atmos, "temperature", H5T_NATIVE_FLOAT, file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName); if (( io.in_atmos_vz = H5Dcreate(ncid_atmos, "velocity_z", H5T_NATIVE_FLOAT, file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName); if (( io.in_atmos_z = H5Dcreate(ncid_atmos, "height", H5T_NATIVE_FLOAT, file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName); if (( H5Pclose(plist) ) < 0) HERR(routineName); if (( H5Sclose(file_dspace) ) < 0) HERR(routineName); /* --- Write some data that does not depend on xi, yi, ATMOS group --- */ /* arrays of number of elements */ eweight = (double *) malloc(atmos.Nelem * sizeof(double)); eabund = (double *) malloc(atmos.Nelem * sizeof(double)); for (i=0; i < atmos.Nelem; i++) { eweight[i] = atmos.elements[i].weight; eabund[i] = atmos.elements[i].abund; } dims[0] = atmos.Nelem; if (( H5LTmake_dataset(ncid_atmos, "element_weight", 1, dims, H5T_NATIVE_DOUBLE, eweight) ) < 0) HERR(routineName); if (( H5LTmake_dataset(ncid_atmos, "element_abundance", 1, dims, H5T_NATIVE_DOUBLE, eabund) ) < 0) HERR(routineName); /* Not writing element_id for now dims[1] = strlen; if (( H5LTmake_dataset(ncid_atmos, "element_id", 2, dims, H5T_C_S1, eID) ) < 0) HERR(routineName); */ free(eweight); free(eabund); dims[0] = geometry.Nrays; if (( H5LTmake_dataset(ncid_atmos, "muz", 1, dims, H5T_NATIVE_DOUBLE, geometry.muz) ) < 0) HERR(routineName); if (( H5LTmake_dataset(ncid_atmos, "wmu", 1, dims, H5T_NATIVE_DOUBLE, geometry.wmu) ) < 0) HERR(routineName); x = (double *) malloc(mpi.nx * sizeof(double)); y = (double *) malloc(mpi.ny * sizeof(double)); for (i=0; i < mpi.nx; i++) x[i] = infile.x[mpi.xnum[i]]; for (i=0; i < mpi.ny; i++) y[i] = infile.y[mpi.ynum[i]]; dims[0] = mpi.nx; if (( H5LTmake_dataset(ncid_atmos, "x", 1, dims, H5T_NATIVE_DOUBLE, x) ) < 0) HERR(routineName); dims[0] = mpi.ny; if (( H5LTmake_dataset(ncid_atmos, "y", 1, dims, H5T_NATIVE_DOUBLE, y) ) < 0) HERR(routineName); free(x); free(y); /* attributes */ if (( H5LTset_attribute_uchar(ncid_atmos, ".", "moving", (unsigned char *) &atmos.moving, 1)) < 0) HERR(routineName); if (( H5LTset_attribute_uchar(ncid_atmos, ".", "stokes", (unsigned char *) &atmos.Stokes, 1)) < 0) HERR(routineName); if (( H5LTset_attribute_string(ncid_atmos, "temperature", "units", "K") ) < 0) HERR(routineName); if (( H5LTset_attribute_string(ncid_atmos, "velocity_z", "units", "m s^-1") ) < 0) HERR(routineName); if (( H5LTset_attribute_string(ncid_atmos, "height", "units", "m") ) < 0) HERR(routineName); if (( H5LTset_attribute_string(ncid_atmos, "element_weight", "units", "atomic_mass_units") ) < 0) HERR(routineName); if (( H5LTset_attribute_string(ncid_atmos, "x", "units", "m") ) < 0) HERR(routineName); if (( H5LTset_attribute_string(ncid_atmos, "y", "units", "m") ) < 0) HERR(routineName); /* --- Definitions for the MPI group --- */ /* dimensions */ if (( H5LTset_attribute_int(ncid_mpi, ".", "nprocesses", &mpi.size, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_mpi, ".", "niterations", &NMaxIter, 1) ) < 0) HERR(routineName); /* variables*/ dims[0] = mpi.nx; if (( H5LTmake_dataset(ncid_mpi, XNUM_NAME, 1, dims, H5T_NATIVE_INT, mpi.xnum) ) < 0) HERR(routineName); dims[0] = mpi.ny; if (( H5LTmake_dataset(ncid_mpi, YNUM_NAME, 1, dims, H5T_NATIVE_INT, mpi.ynum) ) < 0) HERR(routineName); dims[0] = mpi.nx; dims[1] = mpi.ny; if (( file_dspace = H5Screate_simple(2, dims, NULL) ) < 0) HERR(routineName); if (( plist = H5Pcreate(H5P_DATASET_CREATE) ) < 0) HERR(routineName); if (( H5Pset_fill_value(plist, H5T_NATIVE_FLOAT, &FILLVALUE) ) < 0) HERR(routineName); if (( H5Pset_alloc_time(plist, H5D_ALLOC_TIME_EARLY) ) < 0) HERR(routineName); if (( H5Pset_fill_time(plist, H5D_FILL_TIME_ALLOC) ) < 0) HERR(routineName); if (( io.in_mpi_tm = H5Dcreate(ncid_mpi, TASK_MAP, H5T_NATIVE_LONG, file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName); if (( io.in_mpi_tn = H5Dcreate(ncid_mpi, TASK_NUMBER, H5T_NATIVE_LONG, file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName); if (( io.in_mpi_it = H5Dcreate(ncid_mpi, ITER_NAME, H5T_NATIVE_LONG, file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName); if (( io.in_mpi_conv = H5Dcreate(ncid_mpi, CONV_NAME, H5T_NATIVE_LONG, file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName); if (( io.in_mpi_dm = H5Dcreate(ncid_mpi, DM_NAME, H5T_NATIVE_FLOAT, file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName); if (( io.in_mpi_zc = H5Dcreate(ncid_mpi, ZC_NAME, H5T_NATIVE_INT, file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName); if (( H5Pclose(plist) ) < 0) HERR(routineName); if (( H5Sclose(file_dspace) ) < 0) HERR(routineName); dims[0] = mpi.nx; dims[1] = mpi.ny; dims[2] = NMaxIter; if (( file_dspace = H5Screate_simple(3, dims, NULL) ) < 0) HERR(routineName); if (( plist = H5Pcreate(H5P_DATASET_CREATE) ) < 0) HERR(routineName); if (( H5Pset_fill_value(plist, H5T_NATIVE_FLOAT, &FILLVALUE) ) < 0) HERR(routineName); if (( H5Pset_alloc_time(plist, H5D_ALLOC_TIME_EARLY) ) < 0) HERR(routineName); if (( H5Pset_fill_time(plist, H5D_FILL_TIME_ALLOC) ) < 0) HERR(routineName); if (( io.in_mpi_dmh = H5Dcreate(ncid_mpi, DMH_NAME, H5T_NATIVE_FLOAT, file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName); if (( H5Pclose(plist) ) < 0) HERR(routineName); if (( H5Sclose(file_dspace) ) < 0) HERR(routineName); /* attributes */ if (( H5LTset_attribute_int(ncid_mpi, ".", "x_start", &input.p15d_x0, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_mpi, ".", "x_end", &input.p15d_x1, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_mpi, ".", "x_step", &input.p15d_xst, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_mpi, ".", "y_start", &input.p15d_y0, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_mpi, ".", "y_end", &input.p15d_y1, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_mpi, ".", "y_step", &input.p15d_yst, 1) ) < 0) HERR(routineName); /* Tiago: most of the arrays involving Ntasks or rank as index are not currently being written. They should eventually be migrated into arrays of [ix, iy] and be written for each task. This is to avoid causing problems with pool mode, where these quantities are not known from the start. */ /* Flush ensures file is created in case of crash */ if (( H5Fflush(ncid, H5F_SCOPE_LOCAL) ) < 0) HERR(routineName); /* --- Copy stuff to the IO data struct --- */ io.in_ncid = ncid; io.in_input_ncid = ncid_input; io.in_atmos_ncid = ncid_atmos; io.in_mpi_ncid = ncid_mpi; return; }
static int test_dsets( void ) { int rank = 2; hsize_t dims[2] = {2,3}; hid_t file_id; hid_t dataset_id; char data_char_in[DIM] = {1,2,3,4,5,6}; char data_char_out[DIM]; short data_short_in[DIM] = {1,2,3,4,5,6}; short data_short_out[DIM]; int data_int_in[DIM] = {1,2,3,4,5,6}; int data_int_out[DIM]; long data_long_in[DIM] = {1,2,3,4,5,6}; long data_long_out[DIM]; float data_float_in[DIM] = {1,2,3,4,5,6}; float data_float_out[DIM]; double data_double_in[DIM] = {1,2,3,4,5,6}; double data_double_out[DIM]; const char *data_string_in = "This is a string"; char data_string_out[20]; int i; /* Create a new file using default properties. */ file_id = H5Fcreate( FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT ); /*------------------------------------------------------------------------- * H5LTmake_dataset test *------------------------------------------------------------------------- */ TESTING("H5LTmake_dataset"); /* Make dataset */ if ( H5LTmake_dataset( file_id, DSET0_NAME, rank, dims, H5T_NATIVE_INT, data_int_in ) < 0 ) goto out; /* Read dataset using the basic HDF5 API */ if ( ( dataset_id = H5Dopen2(file_id, DSET0_NAME, H5P_DEFAULT) ) < 0 ) goto out; if ( H5Dread ( dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data_int_out ) < 0 ) goto out; if ( H5Dclose( dataset_id ) < 0 ) goto out; for (i = 0; i < DIM; i++) { if ( data_int_in[i] != data_int_out[i] ) { goto out; } } PASSED(); /*------------------------------------------------------------------------- * read using the LT function H5LTread_dataset *------------------------------------------------------------------------- */ TESTING("H5LTread_dataset"); if ( H5LTread_dataset( file_id, DSET0_NAME, H5T_NATIVE_INT, data_int_out ) < 0 ) goto out; for (i = 0; i < DIM; i++) { if ( data_int_in[i] != data_int_out[i] ) { goto out; } } PASSED(); /*------------------------------------------------------------------------- * test the H5LTmake_dataset_ functions *------------------------------------------------------------------------- */ /*------------------------------------------------------------------------- * H5LTmake_dataset_char *------------------------------------------------------------------------- */ TESTING("H5LTmake_dataset_char"); /* Make dataset char */ if ( H5LTmake_dataset_char( file_id, DSET1_NAME, rank, dims, data_char_in ) < 0 ) goto out; /* Read dataset */ if ( H5LTread_dataset( file_id, DSET1_NAME, H5T_NATIVE_CHAR, data_char_out ) < 0 ) goto out; for (i = 0; i < DIM; i++) { if ( data_char_in[i] != data_char_out[i] ) { goto out; } } /* Read dataset */ if ( H5LTread_dataset_char( file_id, DSET1_NAME, data_char_out ) < 0 ) goto out; for (i = 0; i < DIM; i++) { if ( data_char_in[i] != data_char_out[i] ) { goto out; } } PASSED(); /*------------------------------------------------------------------------- * H5LTmake_dataset_short *------------------------------------------------------------------------- */ TESTING("H5LTmake_dataset_short"); /* Make dataset short */ if ( H5LTmake_dataset_short( file_id, DSET2_NAME, rank, dims, data_short_in ) < 0 ) goto out; /* Read dataset */ if ( H5LTread_dataset( file_id, DSET2_NAME, H5T_NATIVE_SHORT, data_short_out ) < 0 ) goto out; for (i = 0; i < DIM; i++) { if ( data_short_in[i] != data_short_out[i] ) { goto out; } } /* Read dataset */ if ( H5LTread_dataset_short( file_id, DSET2_NAME, data_short_out ) < 0 ) goto out; for (i = 0; i < DIM; i++) { if ( data_short_in[i] != data_short_out[i] ) { goto out; } } PASSED(); /*------------------------------------------------------------------------- * H5LTmake_dataset_int *------------------------------------------------------------------------- */ TESTING("H5LTmake_dataset_int"); /* Make dataset int */ if ( H5LTmake_dataset_int( file_id, DSET3_NAME, rank, dims, data_int_in ) < 0 ) goto out; /* Read dataset */ if ( H5LTread_dataset( file_id, DSET3_NAME, H5T_NATIVE_INT, data_int_out ) < 0 ) goto out; for (i = 0; i < DIM; i++) { if ( data_int_in[i] != data_int_out[i] ) { goto out; } } /* Read dataset */ if ( H5LTread_dataset_int( file_id, DSET3_NAME, data_int_out ) < 0 ) goto out; for (i = 0; i < DIM; i++) { if ( data_int_in[i] != data_int_out[i] ) { goto out; } } PASSED(); /*------------------------------------------------------------------------- * H5LTmake_dataset_long *------------------------------------------------------------------------- */ TESTING("H5LTmake_dataset_long"); /* Make dataset long */ if ( H5LTmake_dataset_long( file_id, DSET4_NAME, rank, dims, data_long_in ) < 0 ) goto out; /* Read dataset */ if ( H5LTread_dataset( file_id, DSET4_NAME, H5T_NATIVE_LONG, data_long_out ) < 0 ) goto out; for (i = 0; i < DIM; i++) { if ( data_long_in[i] != data_long_out[i] ) { goto out; } } /* Read dataset */ if ( H5LTread_dataset_long( file_id, DSET4_NAME, data_long_out ) < 0 ) goto out; for (i = 0; i < DIM; i++) { if ( data_long_in[i] != data_long_out[i] ) { goto out; } } PASSED(); /*------------------------------------------------------------------------- * H5LTmake_dataset_float *------------------------------------------------------------------------- */ TESTING("H5LTmake_dataset_float"); /* Make dataset float */ if ( H5LTmake_dataset_float( file_id, DSET5_NAME, rank, dims, data_float_in ) < 0 ) goto out; /* Read dataset */ if ( H5LTread_dataset( file_id, DSET5_NAME, H5T_NATIVE_FLOAT, data_float_out ) < 0 ) goto out; for (i = 0; i < DIM; i++) { if ( data_float_in[i] != data_float_out[i] ) { goto out; } } /* Read dataset */ if ( H5LTread_dataset_float( file_id, DSET5_NAME, data_float_out ) < 0 ) goto out; for (i = 0; i < DIM; i++) { if ( data_float_in[i] != data_float_out[i] ) { goto out; } } PASSED(); /*------------------------------------------------------------------------- * H5LTmake_dataset_double *------------------------------------------------------------------------- */ TESTING("H5LTmake_dataset_double"); /* Make dataset double */ if ( H5LTmake_dataset_double( file_id, DSET6_NAME, rank, dims, data_double_in ) < 0 ) goto out; /* Read dataset */ if ( H5LTread_dataset( file_id, DSET6_NAME, H5T_NATIVE_DOUBLE, data_double_out ) < 0 ) goto out; for (i = 0; i < DIM; i++) { if ( data_double_in[i] != data_double_out[i] ) { goto out; } } /* Read dataset */ if ( H5LTread_dataset_double( file_id, DSET6_NAME, data_double_out ) < 0 ) goto out; for (i = 0; i < DIM; i++) { if ( data_double_in[i] != data_double_out[i] ) { goto out; } } PASSED(); /*------------------------------------------------------------------------- * H5LTmake_dataset_string *------------------------------------------------------------------------- */ TESTING("H5LTmake_dataset_string"); /* Make dataset string */ if ( H5LTmake_dataset_string(file_id,DSET7_NAME,data_string_in) < 0 ) goto out; /* Read dataset */ if ( H5LTread_dataset_string(file_id,DSET7_NAME,data_string_out) < 0 ) goto out; if ( strcmp(data_string_in,data_string_out) != 0 ) goto out; /*------------------------------------------------------------------------- * end tests *------------------------------------------------------------------------- */ /* Close the file. */ H5Fclose( file_id ); PASSED(); return 0; out: /* Close the file. */ H5_FAILED(); return -1; }
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 }
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); }
/* Print the result trajectory that is attached to urdme_model to a mat/hdf5 file. The output trajectory will be stored in a variable/dataset named "U". */ int dump_results(urdme_model* model, char *filename, char *type){ /* IN PYURDME, THIS IS NEVER CALLED. IT IS ALWAYS USING HDF5. */ int Ndofs,tlen,nsol; int *U; U = model->U[0]; Ndofs = model->Ncells*model->Mspecies; tlen = model->tlen; nsol = model->nsol; #ifdef OUTPUT_MAT MATFile *output; mxArray *Uout; #ifndef URDME_OUTPUT_SPARSE Uout = mxCreateDoubleMatrix(Ndofs,tlen,mxREAL); double *data; data = mxGetPr(Uout); /* Dense output data */ for (i=0;i<Ndofs*model->tlen;i++){ data[i]=(double) U[i]; } #else /* If sparse output, we write the matrix on dictionary of keys (DOK) format. The application using this matrix will then have to convert to whatever format needed. the keys are (iU,jU) and values sU. To instantiate a sparse matrix in Matlab, load the output file and do >> U = sparse(iU,jU,sU,mU,nU); */ /* Count number of non-zeros */ int nnz = 0,nnz_col; for (i=0; i<Ndofs*tlen; i++) { if (U[i]>0.0) nnz++; } mxArray* iU = mxCreateDoubleMatrix(nnz,1,mxREAL); mxArray* jU = mxCreateDoubleMatrix(nnz,1,mxREAL); mxArray* sU = mxCreateDoubleMatrix(nnz,1,mxREAL); // Dimesions of the matrix, mU (row) and nU(col). In-house matlib does not have mxCreateScalar. mxArray* mU = mxCreateDoubleMatrix(1,1,mxREAL); double *dim; dim = mxGetPr(mU); dim[0] = (double)Ndofs; mxArray* nU = mxCreateDoubleMatrix(1,1,mxREAL); dim = mxGetPr(nU); dim[0] = (double)tlen; double *iUdata = mxGetPr(iU); double *jUdata = mxGetPr(jU); double *sUdata = mxGetPr(sU); nnz = 0; for (j=0; j<tlen; j++){ for (i=0;i<Ndofs;i++){ if (U[j*Ndofs+i]>0.0){ /* NOTE THE +1 HERE, MATLAB SPECIFIC INDEXING. */ iUdata[nnz] = (double)(i+1); jUdata[nnz] = (double)(j+1); sUdata[nnz] = (double)U[j*Ndofs+i]; nnz++; } } } #endif mxArray *Tspanout; Tspanout = mxCreateDoubleMatrix(1, model->tlen,mxREAL); double *tdata; tdata = mxGetPr(Tspanout); for(i=0;i<model->tlen;i++) tdata[i]=model->tspan[i]; #ifdef URDME_LIBMAT output = matOpen(filename,"w"); // using built in URDME mat read/write #else output = matOpen(filename,"w7.3"); // Possibly large files #endif if (output == NULL){ printf("Error: Could not write to output file: %s\n",filename); return(-1); } #ifndef URDME_OUTPUT_SPARSE matPutVariable(output,"U",Uout); matPutVariable(output,"tspan",Tspanout); #else matPutVariable(output,"iU",iU); matPutVariable(output,"jU",jU); matPutVariable(output,"sU",sU); matPutVariable(output,"mU",mU); matPutVariable(output,"nU",nU); matPutVariable(output,"tspan",Tspanout); #endif matClose(output); #ifndef URDME_OUTPUT_SPARSE mxDestroyArray(Uout); mxDestroyArray(Tspanout); #else mxDestroyArray(iU); mxDestroyArray(jU); mxDestroyArray(sU); mxDestroyArray(Tspanout); mxDestroyArray(mU); mxDestroyArray(nU); #endif #elif defined(OUTPUT_HDF5) /* Write the result as a HDF5 dataset/file */ hid_t h5_output_file; herr_t status; h5_output_file = H5Fcreate(filename,H5F_ACC_TRUNC, H5P_DEFAULT,H5P_DEFAULT); if (h5_output_file == NULL){ printf("Failed to write U matrix HDF5 file."); exit(-1); } hsize_t dims[2]; /* dataset dimensions */ dims[0] = Ndofs; dims[1] = tlen; // Write the result matrix to the file status = H5LTmake_dataset(h5_output_file,"/U",2,dims,H5T_NATIVE_INT,U); if (status != 0){ printf("Failed to write U matrix HDF5 file."); exit(-1); } // Write tspan to the file dims[0] = 1; dims[1] = tlen; status = H5LTmake_dataset(h5_output_file,"/tspan",2,dims,H5T_NATIVE_DOUBLE,model->tspan); if (status != 0){ printf("Failed to write tspan vector HDF5 file."); exit(-1); } status = H5Fclose(h5_output_file); if (status != 0){ printf("Failed to close output HDF5 file."); exit(-1); } #endif return 1; }
OPENPSTD_SHARED_EXPORT void HDF5::ExportData(std::string format, std::shared_ptr <PSTDFile> file, std::string output, std::vector<int> domains, int startFrame, int endFrame) { hid_t file_id; Kernel::MockKernel k; file_id = H5Fcreate(output.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); hid_t frame_dir_id = H5Gcreate2(file_id, "/frame", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); hid_t receiver_dir_id = H5Gcreate2(file_id, "/receiver", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); k.initialize_kernel(file->GetSceneConf(), std::make_shared<OpenPSTD::Kernel::KernelCallbackLog>()); auto metadata = k.get_metadata(); if (domains.size() == 0) { int domainCount = file->GetResultsDomainCount(); for (int d = 0; d < domainCount; ++d) { domains.push_back(d); } } for(int d : domains) { std::string domainLoc = "/frame/" + boost::lexical_cast<std::string>(d); hid_t frame_index_id = H5Gcreate2(file_id, domainLoc.c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); if (startFrame == -1) startFrame = 0; if (endFrame == -1) endFrame = file->GetResultsFrameCount(d) - 1; for (int f = startFrame; f <= endFrame; ++f) { std::string location = domainLoc + "/" + boost::lexical_cast<std::string>(f); std::vector<hsize_t> size; size.push_back(metadata.DomainMetadata[d][0]); size.push_back(metadata.DomainMetadata[d][1]); //get data and write to file auto data = file->GetResultsFrame(f, d); H5LTmake_dataset(file_id, location.c_str(), 2, size.data(), H5T_NATIVE_FLOAT, data->data()); } H5Gclose(frame_index_id); } int receiverCount = file->GetResultsReceiverCount(); for(int r = 0; r < receiverCount; r++) { std::string receiverLoc = "/receiver/" + boost::lexical_cast<std::string>(r); auto data = file->GetReceiverData(r); std::vector<hsize_t> size; size.push_back(data->size()); H5LTmake_dataset(file_id, receiverLoc.c_str(), 1, size.data(), H5T_NATIVE_FLOAT, data->data()); } /* close file */ H5Gclose(frame_dir_id); H5Gclose(receiver_dir_id); H5Fclose (file_id); }
void PHDF5fileClass::CreatePHDF5file(double *L, int *dglob, int *dlocl, bool bp){ hid_t acc_t; hid_t Ldataspace; hid_t Ldataset; hid_t ndataspace; hid_t ndataset; herr_t status; hsize_t d[1]; /* ---------------------------------------------- */ /* 0- Initialize the some of the class parameters */ /* ---------------------------------------------- */ bparticles = bp; for (int i=0; i<ndim; i++){ LxLyLz[i] = L[i]; dim[i] = (hsize_t)dglob[i]; chdim[i] = (hsize_t)dlocl[i]; } /* ----------------------------------------------------- */ /* 1- Set the access template for the parallel HDF5 file */ /* ----------------------------------------------------- */ acc_t = H5Pcreate(H5P_FILE_ACCESS); /* --------------------------------------- */ /* 2- Tell HDF5 that we want to use MPI-IO */ /* --------------------------------------- */ H5Pset_fapl_mpio(acc_t, comm, MPI_INFO_NULL); /* ------------------------------------------------------- */ /* 3- Load file identifier and release the access template */ /* ------------------------------------------------------- */ file_id = H5Fcreate(filename.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, acc_t); H5Pclose(acc_t); /* -------------------- */ /* 4- Set up the groups */ /* -------------------- */ for (int i=0; i<ngrp; i++){ if (!(grpnames[i]=="Particles"&&!bparticles)){ hid_t grp; grp = H5Gcreate2(file_id, grpnames[i].c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Gclose(grp); } } /* -------------------------------------- */ /* Create and fill the Parameters dataset */ /* -------------------------------------- */ d[0] = 3; status = H5LTmake_dataset(file_id, "/Parameters/LxLyLz", 1, d, H5T_NATIVE_DOUBLE, LxLyLz); status = H5LTmake_dataset(file_id, "/Parameters/ncell" , 1, d, H5T_NATIVE_INT , dglob); }
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; }