diff --git a/src/common_io.c b/src/common_io.c index 143c1ca94160f2a43c40aa44384803ce721e4dbf..4399c83f7ebd2bb5355b7df9cc1fdecd301e36aa 100644 --- a/src/common_io.c +++ b/src/common_io.c @@ -147,8 +147,8 @@ void readAttribute(hid_t grp, char* name, enum DATA_TYPE type, void* data) { * * Calls #error() if an error occurs. */ -void writeAttribute(hid_t grp, char* name, enum DATA_TYPE type, void* data, - int num) { +void writeAttribute(hid_t grp, const char* name, enum DATA_TYPE type, + void* data, int num) { hid_t h_space = 0, h_attr = 0, h_err = 0; hsize_t dim[1] = {num}; @@ -186,7 +186,8 @@ void writeAttribute(hid_t grp, char* name, enum DATA_TYPE type, void* data, * * Calls #error() if an error occurs. */ -void writeStringAttribute(hid_t grp, char* name, const char* str, int length) { +void writeStringAttribute(hid_t grp, const char* name, const char* str, + int length) { hid_t h_space = 0, h_attr = 0, h_err = 0, h_type = 0; h_space = H5Screate(H5S_SCALAR); @@ -225,7 +226,7 @@ void writeStringAttribute(hid_t grp, char* name, const char* str, int length) { * @param name The name of the attribute * @param data The value to write */ -void writeAttribute_d(hid_t grp, char* name, double data) { +void writeAttribute_d(hid_t grp, const char* name, double data) { writeAttribute(grp, name, DOUBLE, &data, 1); } @@ -235,7 +236,7 @@ void writeAttribute_d(hid_t grp, char* name, double data) { * @param name The name of the attribute * @param data The value to write */ -void writeAttribute_f(hid_t grp, char* name, float data) { +void writeAttribute_f(hid_t grp, const char* name, float data) { writeAttribute(grp, name, FLOAT, &data, 1); } @@ -246,7 +247,7 @@ void writeAttribute_f(hid_t grp, char* name, float data) { * @param data The value to write */ -void writeAttribute_i(hid_t grp, char* name, int data) { +void writeAttribute_i(hid_t grp, const char* name, int data) { writeAttribute(grp, name, INT, &data, 1); } @@ -256,7 +257,7 @@ void writeAttribute_i(hid_t grp, char* name, int data) { * @param name The name of the attribute * @param data The value to write */ -void writeAttribute_l(hid_t grp, char* name, long data) { +void writeAttribute_l(hid_t grp, const char* name, long data) { writeAttribute(grp, name, LONG, &data, 1); } @@ -266,7 +267,7 @@ void writeAttribute_l(hid_t grp, char* name, long data) { * @param name The name of the attribute * @param str The string to write */ -void writeAttribute_s(hid_t grp, char* name, const char* str) { +void writeAttribute_s(hid_t grp, const char* name, const char* str) { writeStringAttribute(grp, name, str, strlen(str)); } diff --git a/src/common_io.h b/src/common_io.h index 334349ccccb85344cc250b24c2a68dc4a455b77d..6dbb83e74771dacf6b61f697a5c177781db443ec 100644 --- a/src/common_io.h +++ b/src/common_io.h @@ -88,14 +88,14 @@ void duplicate_hydro_gparts(struct part* const parts, void readAttribute(hid_t grp, char* name, enum DATA_TYPE type, void* data); -void writeAttribute(hid_t grp, char* name, enum DATA_TYPE type, void* data, - int num); - -void writeAttribute_d(hid_t grp, char* name, double data); -void writeAttribute_f(hid_t grp, char* name, float data); -void writeAttribute_i(hid_t grp, char* name, int data); -void writeAttribute_l(hid_t grp, char* name, long data); -void writeAttribute_s(hid_t grp, char* name, const char* str); +void writeAttribute(hid_t grp, const char* name, enum DATA_TYPE type, + void* data, int num); + +void writeAttribute_d(hid_t grp, const char* name, double data); +void writeAttribute_f(hid_t grp, const char* name, float data); +void writeAttribute_i(hid_t grp, const char* name, int data); +void writeAttribute_l(hid_t grp, const char* name, long data); +void writeAttribute_s(hid_t grp, const char* name, const char* str); void createXMFfile(const char* baseName); FILE* prepareXMFfile(const char* baseName); diff --git a/src/parallel_io.c b/src/parallel_io.c index 4579be8f04ae687140413383e061988c9783b570..e779b56a85da3db72ea860fb336fa42037fbcd0e 100644 --- a/src/parallel_io.c +++ b/src/parallel_io.c @@ -529,7 +529,7 @@ void read_ic_parallel(char* fileName, double dim[3], struct part** parts, void write_output_parallel(struct engine* e, const char* baseName, struct UnitSystem* us, int mpi_rank, int mpi_size, MPI_Comm comm, MPI_Info info) { - hid_t h_file = 0, h_grp = 0, h_grpsph = 0; + hid_t h_file = 0, h_grp = 0; const size_t Ngas = e->s->nr_parts; const size_t Ntot = e->s->nr_gparts; int periodic = e->s->periodic; @@ -633,10 +633,17 @@ void write_output_parallel(struct engine* e, const char* baseName, writeCodeDescription(h_file); /* Print the SPH parameters */ - h_grpsph = H5Gcreate(h_file, "/SPH", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); - if (h_grpsph < 0) error("Error while creating SPH group"); - writeSPHflavour(h_grpsph); - H5Gclose(h_grpsph); + h_grp = H5Gcreate(h_file, "/SPH", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + if (h_grp < 0) error("Error while creating SPH group"); + writeSPHflavour(h_grp); + H5Gclose(h_grp); + + /* Print the runtime parameters */ + h_grp = + H5Gcreate(h_file, "/Parameters", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + if (h_grp < 0) error("Error while creating parameters group"); + parser_write_params_to_hdf5(e->parameter_file, h_grp); + H5Gclose(h_grp); /* Print the system of Units */ writeUnitSystem(h_file, us); diff --git a/src/parser.c b/src/parser.c index c73040b903d3e8c0280f37c05ac67b0b4e9029ed..28acb4f7530d1aab6be577b005978df7e05bef0e 100644 --- a/src/parser.c +++ b/src/parser.c @@ -31,6 +31,7 @@ /* Local headers. */ #include "error.h" +#include "common_io.h" #define PARSER_COMMENT_STRING "#" #define PARSER_COMMENT_CHAR '#' @@ -580,3 +581,11 @@ void parser_write_params_to_file(const struct swift_params *params, fclose(file); } + +#if defined(HAVE_HDF5) +void parser_write_params_to_hdf5(const struct swift_params *params, hid_t grp) { + + for (int i = 0; i < params->paramCount; i++) + writeAttribute_s(grp, params->data[i].name, params->data[i].value); +} +#endif diff --git a/src/serial_io.c b/src/serial_io.c index f2c0dcce1cc258e7c9a43027fbdd45e299b47ae6..5abd3ebc28672d68c4135efe5753dc4713c2d3c6 100644 --- a/src/serial_io.c +++ b/src/serial_io.c @@ -608,7 +608,7 @@ void read_ic_serial(char* fileName, double dim[3], struct part** parts, void write_output_serial(struct engine* e, const char* baseName, struct UnitSystem* us, int mpi_rank, int mpi_size, MPI_Comm comm, MPI_Info info) { - hid_t h_file = 0, h_grp = 0, h_grpsph = 0; + hid_t h_file = 0, h_grp = 0; const size_t Ngas = e->s->nr_parts; const size_t Ntot = e->s->nr_gparts; int periodic = e->s->periodic; @@ -710,10 +710,17 @@ void write_output_serial(struct engine* e, const char* baseName, writeCodeDescription(h_file); /* Print the SPH parameters */ - h_grpsph = H5Gcreate(h_file, "/SPH", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); - if (h_grpsph < 0) error("Error while creating SPH group"); - writeSPHflavour(h_grpsph); - H5Gclose(h_grpsph); + h_grp = H5Gcreate(h_file, "/SPH", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + if (h_grp < 0) error("Error while creating SPH group"); + writeSPHflavour(h_grp); + H5Gclose(h_grp); + + /* Print the runtime parameters */ + h_grp = + H5Gcreate(h_file, "/Parameters", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + if (h_grp < 0) error("Error while creating parameters group"); + parser_write_params_to_hdf5(e->parameter_file, h_grp); + H5Gclose(h_grp); /* Print the system of Units */ writeUnitSystem(h_file, us); diff --git a/src/single_io.c b/src/single_io.c index 94ef4e59c0ede0cba2b09b9342b538d0efa042b7..14f7209dd41f03abe3a66f38511029edab40fc2e 100644 --- a/src/single_io.c +++ b/src/single_io.c @@ -563,7 +563,8 @@ void write_output_single(struct engine* e, const char* baseName, H5Gclose(h_grp); /* Print the runtime parameters */ - h_grp = H5Gcreate(h_file, "/Parameters", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + h_grp = + H5Gcreate(h_file, "/Parameters", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); if (h_grp < 0) error("Error while creating parameters group"); parser_write_params_to_hdf5(e->parameter_file, h_grp); H5Gclose(h_grp);