Skip to content
Snippets Groups Projects
Commit 643f31e3 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

The parameter file is now written to the HDF5 snapshots as attributes.

parent b6e8d2b6
No related branches found
No related tags found
1 merge request!173Parameter file in snapshot
......@@ -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));
}
......
......@@ -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);
......
......@@ -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);
......
......@@ -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
......@@ -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);
......
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment