Commit 65f08533 authored by Peter W. Draper's avatar Peter W. Draper
Browse files

Formatting

parent a6c5eefe
......@@ -60,14 +60,12 @@ void cooling_print(const struct cooling_function_data* cooling) {
* @param p the struct
* @param stream the file stream
*/
void cooling_struct_dump(const struct cooling_function_data* cooling,
FILE *stream) {
restart_write_blocks((void *) cooling,
sizeof(struct cooling_function_data),
1, stream, "cooling function");
void cooling_struct_dump(const struct cooling_function_data* cooling,
FILE* stream) {
restart_write_blocks((void*)cooling, sizeof(struct cooling_function_data), 1,
stream, "cooling function");
}
/**
* @brief Restore a hydro_props struct from the given FILE as a stream of
* bytes.
......@@ -76,7 +74,7 @@ void cooling_struct_dump(const struct cooling_function_data* cooling,
* @param stream the file stream
*/
void cooling_struct_restore(const struct cooling_function_data* cooling,
FILE *stream) {
restart_read_blocks((void *)cooling, sizeof(struct cooling_function_data),
1, stream, "cooling function");
FILE* stream) {
restart_read_blocks((void*)cooling, sizeof(struct cooling_function_data), 1,
stream, "cooling function");
}
......@@ -49,7 +49,9 @@ void cooling_init(const struct swift_params* parameter_file,
void cooling_print(const struct cooling_function_data* cooling);
/* Dump/restore. */
void cooling_struct_dump(const struct cooling_function_data* cooling, FILE *stream);
void cooling_struct_restore(const struct cooling_function_data* cooling, FILE *stream);
void cooling_struct_dump(const struct cooling_function_data* cooling,
FILE* stream);
void cooling_struct_restore(const struct cooling_function_data* cooling,
FILE* stream);
#endif /* SWIFT_COOLING_H */
......@@ -5638,7 +5638,7 @@ void engine_clean(struct engine *e) {
void engine_struct_dump(struct engine *e, FILE *stream) {
/* Dump our signature and version. */
restart_write_blocks(SWIFT_RESTART_SIGNATURE,strlen(SWIFT_RESTART_SIGNATURE),
restart_write_blocks(SWIFT_RESTART_SIGNATURE, strlen(SWIFT_RESTART_SIGNATURE),
1, stream, "SWIFT signature");
restart_write_blocks((void *)package_version(), strlen(package_version()), 1,
stream, "SWIFT version");
......@@ -5648,7 +5648,6 @@ void engine_struct_dump(struct engine *e, FILE *stream) {
/* And all the engine pointed data, these use their own dump functions. */
space_struct_dump(e->s, stream);
e->s->e = e;
units_struct_dump(e->internal_units, stream);
units_struct_dump(e->snapshotUnits, stream);
partition_struct_dump(e->reparttype, stream);
......@@ -5671,9 +5670,9 @@ void engine_struct_dump(struct engine *e, FILE *stream) {
void engine_struct_restore(struct engine *e, FILE *stream) {
/* Get our version and signature back. These should match. */
char signature[10];
restart_write_blocks(signature, strlen(SWIFT_RESTART_SIGNATURE), 1, stream,
"SWIFT signature");
char signature[strlen(SWIFT_RESTART_SIGNATURE) + 1];
restart_read_blocks(signature, strlen(SWIFT_RESTART_SIGNATURE), 1, stream,
"SWIFT signature");
if (strcmp(signature, SWIFT_RESTART_SIGNATURE) != 0)
error("Do not recognise this as a SWIFT restart file");
......@@ -5682,14 +5681,17 @@ void engine_struct_restore(struct engine *e, FILE *stream) {
"SWIFT version");
/* XXX error or warning, it might work! */
if (strcmp(version, package_version()) != 0)
message("WARNING: restoring from a different version of SWIFT. You have:"
" %s, and the restarts file where created using: %s. This may fail"
" badly", version, package_version());
message(
"WARNING: restoring from a different version of SWIFT. You have:"
" %s, and the restarts file where created using: %s. This may fail"
" badly",
version, package_version());
/* Now the engine. */
restart_read_blocks(e, sizeof(struct engine), 1, stream, "engine struct");
/* XXX Re-initializations as necessary. XXX */
/* XXX Reopen output files and append... XXX */
/* runners */
/* scheduler */
/* threadpool */
......@@ -5703,21 +5705,55 @@ void engine_struct_restore(struct engine *e, FILE *stream) {
/* links */
/* Now for the other pointers, these use their own restore functions. */
/* XXX struct leaky memory allocations, or need static decls from main.c,
* like engine_init() */
space_struct_restore(e->s, stream);
units_struct_restore(e->internal_units, stream);
units_struct_restore(e->snapshotUnits, stream);
partition_struct_restore(e->reparttype, stream);
phys_const_struct_restore(e->physical_constants, stream);
hydro_props_struct_restore(e->hydro_properties, stream);
gravity_props_struct_restore(e->gravity_properties, stream);
potential_struct_restore(e->external_potential, stream);
cooling_struct_restore(e->cooling_func, stream);
sourceterms_struct_restore(e->sourceterms, stream);
/* Note all this memory leaks, but is used once. */
struct space *s = malloc(sizeof(struct space));
space_struct_restore(s, stream);
e->s = s;
s->e = e;
struct unit_system *us = malloc(sizeof(struct unit_system));
units_struct_restore(us, stream);
e->internal_units = us;
us = malloc(sizeof(struct unit_system));
units_struct_restore(us, stream);
e->snapshotUnits = us;
struct repartition *reparttype = malloc(sizeof(struct repartition));
partition_struct_restore(reparttype, stream);
e->reparttype = reparttype;
struct phys_const *physical_constants = malloc(sizeof(struct phys_const));
phys_const_struct_restore(physical_constants, stream);
e->physical_constants = physical_constants;
struct hydro_props *hydro_properties = malloc(sizeof(struct hydro_props));
hydro_props_struct_restore(hydro_properties, stream);
e->hydro_properties = hydro_properties;
struct gravity_props *gravity_properties =
malloc(sizeof(struct gravity_props));
gravity_props_struct_restore(gravity_properties, stream);
e->gravity_properties = gravity_properties;
struct external_potential *external_potential =
malloc(sizeof(struct external_potential));
potential_struct_restore(external_potential, stream);
e->external_potential = external_potential;
struct cooling_function_data *cooling_func =
malloc(sizeof(struct cooling_function_data));
cooling_struct_restore(cooling_func, stream);
e->cooling_func = cooling_func;
struct sourceterms *sourceterms = malloc(sizeof(struct sourceterms));
sourceterms_struct_restore(sourceterms, stream);
e->sourceterms = sourceterms;
struct swift_params *parameter_file = malloc(sizeof(struct swift_params));
parser_struct_restore(e->parameter_file, stream);
e->parameter_file = parameter_file;
/* Want to force a rebuild before using this engine. Wait to repartition.*/
e->forcerebuild = 1;
......
......@@ -336,5 +336,4 @@ int engine_estimate_nr_tasks(struct engine *e);
void engine_struct_dump(struct engine *e, FILE *stream);
void engine_struct_restore(struct engine *e, FILE *stream);
#endif /* SWIFT_ENGINE_H */
......@@ -104,11 +104,10 @@ void gravity_props_print_snapshot(hid_t h_grpgrav,
* @param stream the file stream
*/
void gravity_props_struct_dump(const struct gravity_props *p, FILE *stream) {
restart_write_blocks((void *) p, sizeof(struct gravity_props),
1, stream, "gravity props");
restart_write_blocks((void *)p, sizeof(struct gravity_props), 1, stream,
"gravity props");
}
/**
* @brief Restore a gravity_props struct from the given FILE as a stream of
* bytes.
......@@ -117,6 +116,6 @@ void gravity_props_struct_dump(const struct gravity_props *p, FILE *stream) {
* @param stream the file stream
*/
void gravity_props_struct_restore(const struct gravity_props *p, FILE *stream) {
restart_read_blocks((void *)p, sizeof(struct gravity_props),
1, stream, "gravity props");
restart_read_blocks((void *)p, sizeof(struct gravity_props), 1, stream,
"gravity props");
}
......@@ -135,11 +135,10 @@ void hydro_props_print_snapshot(hid_t h_grpsph, const struct hydro_props *p) {
* @param stream the file stream
*/
void hydro_props_struct_dump(const struct hydro_props *p, FILE *stream) {
restart_write_blocks((void *) p, sizeof(struct hydro_props),
1, stream, "hydro props");
restart_write_blocks((void *)p, sizeof(struct hydro_props), 1, stream,
"hydro props");
}
/**
* @brief Restore a hydro_props struct from the given FILE as a stream of
* bytes.
......@@ -148,6 +147,6 @@ void hydro_props_struct_dump(const struct hydro_props *p, FILE *stream) {
* @param stream the file stream
*/
void hydro_props_struct_restore(const struct hydro_props *p, FILE *stream) {
restart_read_blocks((void *)p, sizeof(struct hydro_props),
1, stream, "hydro props");
restart_read_blocks((void *)p, sizeof(struct hydro_props), 1, stream,
"hydro props");
}
......@@ -786,7 +786,6 @@ void parser_write_params_to_hdf5(const struct swift_params *params, hid_t grp) {
}
#endif
/**
* @brief Write a swift_params struct to the given FILE as a stream of bytes.
*
......@@ -794,11 +793,10 @@ void parser_write_params_to_hdf5(const struct swift_params *params, hid_t grp) {
* @param stream the file stream
*/
void parser_struct_dump(const struct swift_params *params, FILE *stream) {
restart_write_blocks((void *) params, sizeof(struct swift_params),
1, stream, "parameters");
restart_write_blocks((void *)params, sizeof(struct swift_params), 1, stream,
"parameters");
}
/**
* @brief Restore a swift_params struct from the given FILE as a stream of
* bytes.
......@@ -807,6 +805,6 @@ void parser_struct_dump(const struct swift_params *params, FILE *stream) {
* @param stream the file stream
*/
void parser_struct_restore(const struct swift_params *params, FILE *stream) {
restart_read_blocks((void *)params, sizeof(struct swift_params),
1, stream, "parameters");
restart_read_blocks((void *)params, sizeof(struct swift_params), 1, stream,
"parameters");
}
......@@ -87,5 +87,4 @@ void parser_write_params_to_hdf5(const struct swift_params *params, hid_t grp);
void parser_struct_dump(const struct swift_params *params, FILE *stream);
void parser_struct_restore(const struct swift_params *params, FILE *stream);
#endif /* SWIFT_PARSER_H */
......@@ -1259,11 +1259,10 @@ int partition_space_to_space(double *oldh, double *oldcdim, int *oldnodeIDs,
* @param stream the file stream
*/
void partition_struct_dump(struct repartition *reparttype, FILE *stream) {
restart_write_blocks(reparttype, sizeof(struct repartition), 1, stream,
restart_write_blocks(reparttype, sizeof(struct repartition), 1, stream,
"repartition params");
}
/**
* @brief Restore a repartition struct from the given FILE as a stream of
* bytes.
......
......@@ -35,8 +35,8 @@
* @param us The current internal system of units.
* @param internal_const The physical constants to initialize.
*/
void phys_const_init(struct unit_system* us,
struct phys_const* internal_const) {
void phys_const_init(struct unit_system *us,
struct phys_const *internal_const) {
/* Units are declared as {U_M, U_L, U_t, U_I, U_T} */
......@@ -106,7 +106,7 @@ void phys_const_init(struct unit_system* us,
units_general_cgs_conversion_factor(us, dimension_length);
}
void phys_const_print(struct phys_const* internal_const) {
void phys_const_print(struct phys_const *internal_const) {
message("%25s = %e", "Gravitational constant",
internal_const->const_newton_G);
......@@ -131,11 +131,10 @@ void phys_const_print(struct phys_const* internal_const) {
*/
void phys_const_struct_dump(const struct phys_const *internal_const,
FILE *stream) {
restart_write_blocks((void *) internal_const, sizeof(struct phys_const),
1, stream, "phys_const params");
restart_write_blocks((void *)internal_const, sizeof(struct phys_const), 1,
stream, "phys_const params");
}
/**
* @brief Restore a phys_const struct from the given FILE as a stream of
* bytes.
......@@ -145,6 +144,6 @@ void phys_const_struct_dump(const struct phys_const *internal_const,
*/
void phys_const_struct_restore(const struct phys_const *internal_const,
FILE *stream) {
restart_read_blocks((void *)internal_const, sizeof(struct phys_const),
1, stream, "phys_const params");
restart_read_blocks((void *)internal_const, sizeof(struct phys_const), 1,
stream, "phys_const params");
}
......@@ -83,7 +83,9 @@ void phys_const_init(struct unit_system* us, struct phys_const* internal_const);
void phys_const_print(struct phys_const* internal_const);
/* Dump/restore. */
void phys_const_struct_dump(const struct phys_const* internal_const, FILE *stream);
void phys_const_struct_restore(const struct phys_const* internal_const, FILE *stream);
void phys_const_struct_dump(const struct phys_const* internal_const,
FILE* stream);
void phys_const_struct_restore(const struct phys_const* internal_const,
FILE* stream);
#endif /* SWIFT_PHYSICAL_CONSTANTS_H */
......@@ -53,20 +53,19 @@ void potential_print(const struct external_potential* potential) {
potential_print_backend(potential);
}
/**
* @brief Write an external_potential struct to the given FILE as a stream of bytes.
* @brief Write an external_potential struct to the given FILE as a stream of
* bytes.
*
* @param potential the struct
* @param stream the file stream
*/
void potential_struct_dump(const struct external_potential *potential,
FILE *stream) {
restart_write_blocks((void *) potential, sizeof(struct external_potential),
1, stream, "external potential");
void potential_struct_dump(const struct external_potential* potential,
FILE* stream) {
restart_write_blocks((void*)potential, sizeof(struct external_potential), 1,
stream, "external potential");
}
/**
* @brief Restore a external_potential struct from the given FILE as a stream of
* bytes.
......@@ -74,8 +73,8 @@ void potential_struct_dump(const struct external_potential *potential,
* @param p the struct
* @param stream the file stream
*/
void potential_struct_restore(const struct external_potential *potential,
FILE *stream) {
restart_read_blocks((void *) potential, sizeof(struct external_potential),
1, stream, "external potential");
void potential_struct_restore(const struct external_potential* potential,
FILE* stream) {
restart_read_blocks((void*)potential, sizeof(struct external_potential), 1,
stream, "external potential");
}
......@@ -51,7 +51,9 @@ void potential_init(const struct swift_params* parameter_file,
void potential_print(const struct external_potential* potential);
/* Dump/restore. */
void potential_struct_dump(const struct external_potential* potential, FILE *stream);
void potential_struct_restore(const struct external_potential* potential, FILE *stream);
void potential_struct_dump(const struct external_potential* potential,
FILE* stream);
void potential_struct_restore(const struct external_potential* potential,
FILE* stream);
#endif /* SWIFT_POTENTIAL_H */
......@@ -27,10 +27,10 @@
/* Standard headers. */
#include <errno.h>
#include <glob.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <glob.h>
#include "engine.h"
#include "error.h"
......@@ -47,8 +47,8 @@
*
* @result 0 if the string was large enough.
*/
int restart_genname(const char *dir, const char *basename,
int nodeID, char *name, int size) {
int restart_genname(const char *dir, const char *basename, int nodeID,
char *name, int size) {
int n = snprintf(name, size, "%s/%s_%04d.rst", dir, basename, nodeID);
message("name = %s", name);
return (n >= size);
......@@ -64,8 +64,7 @@ int restart_genname(const char *dir, const char *basename,
* @result pointer to an array of strings with all the filenames found,
* release by calling restart_locate_free().
*/
char **restart_locate(const char *dir, const char *basename,
int *nfiles) {
char **restart_locate(const char *dir, const char *basename, int *nfiles) {
*nfiles = 0;
/* Construct the glob pattern for locating files. */
......@@ -90,7 +89,6 @@ char **restart_locate(const char *dir, const char *basename,
return NULL;
}
/**
* @brief Release the memory allocated to hold the restart file names.
*
......@@ -99,12 +97,11 @@ char **restart_locate(const char *dir, const char *basename,
*/
void restart_locate_free(int nfiles, char **files) {
for (int i = 0; i < nfiles; i++) {
free(files[i]);
free(files[i]);
}
free(files);
}
/**
* @brief Write a restart file for the given engine struct.
*/
......
......@@ -33,11 +33,12 @@ void restart_read(struct engine *e, const char *filename);
char **restart_locate(const char *dir, const char *basename, int *nfiles);
void restart_locate_free(int nfiles, char **files);
int restart_genname(const char *dir, const char *basename,
int nodeID, char *name, int size);
int restart_genname(const char *dir, const char *basename, int nodeID,
char *name, int size);
void restart_read_blocks(void *ptr, size_t size, size_t nblocks, FILE *stream,
const char *errstr);
void restart_write_blocks(void *ptr, size_t size, size_t nblocks, FILE *stream,
const char *errstr);
......
......@@ -36,8 +36,8 @@
* @param us The current internal system of units
* @param source the structure that has all the source term properties
*/
void sourceterms_init(const struct swift_params* parameter_file,
struct unit_system* us, struct sourceterms* source) {
void sourceterms_init(const struct swift_params *parameter_file,
struct unit_system *us, struct sourceterms *source) {
#ifdef SOURCETERMS_SN_FEEDBACK
supernova_init(parameter_file, us, source);
#endif /* SOURCETERMS_SN_FEEDBACK */
......@@ -47,7 +47,7 @@ void sourceterms_init(const struct swift_params* parameter_file,
* @brief Prints the properties of the source terms to stdout
* @param source the structure that has all the source term properties
*/
void sourceterms_print(struct sourceterms* source) {
void sourceterms_print(struct sourceterms *source) {
#ifdef SOURCETERMS_NONE
error(" no sourceterms defined yet you ran with -F");
#ifdef SOURCETERMS_SN_FEEDBACK
......@@ -67,11 +67,10 @@ void sourceterms_print(struct sourceterms* source) {
*/
void sourceterms_struct_dump(const struct sourceterms *sourceterms,
FILE *stream) {
restart_write_blocks((void *) sourceterms, sizeof(struct sourceterms),
1, stream, "sourceterms");
restart_write_blocks((void *)sourceterms, sizeof(struct sourceterms), 1,
stream, "sourceterms");
}
/**
* @brief Restore a sourceterms struct from the given FILE as a stream of
* bytes.
......@@ -81,6 +80,6 @@ void sourceterms_struct_dump(const struct sourceterms *sourceterms,
*/
void sourceterms_struct_restore(const struct sourceterms *sourceterms,
FILE *stream) {
restart_read_blocks((void *)sourceterms, sizeof(struct sourceterms),
1, stream, "sourceterms");
restart_read_blocks((void *)sourceterms, sizeof(struct sourceterms), 1,
stream, "sourceterms");
}
......@@ -46,9 +46,8 @@ void sourceterms_init(const struct swift_params* parameter_file,
void sourceterms_print(struct sourceterms* source);
/* Dump/restore. */
void sourceterms_struct_dump(const struct sourceterms *source, FILE *stream);
void sourceterms_struct_restore(const struct sourceterms *source, FILE *stream);
void sourceterms_struct_dump(const struct sourceterms* source, FILE* stream);
void sourceterms_struct_restore(const struct sourceterms* source, FILE* stream);
/**
* @brief Routines related to source terms
......
......@@ -3251,14 +3251,18 @@ void space_struct_dump(struct space *s, FILE *stream) {
/* More things to write. */
if (s->nr_parts > 0) {
restart_write_blocks(s->parts, s->nr_parts, sizeof(struct part), stream, "parts");
restart_write_blocks(s->xparts, s->nr_parts, sizeof(struct xpart), stream, "xparts");
restart_write_blocks(s->parts, s->nr_parts, sizeof(struct part), stream,
"parts");
restart_write_blocks(s->xparts, s->nr_parts, sizeof(struct xpart), stream,
"xparts");
}
if (s->nr_gparts > 0)
restart_write_blocks(s->gparts, s->nr_gparts, sizeof(struct gpart), stream, "gparts");
restart_write_blocks(s->gparts, s->nr_gparts, sizeof(struct gpart), stream,
"gparts");
if (s->nr_sparts > 0)
restart_write_blocks(s->sparts, s->nr_sparts, sizeof(struct spart), stream, "sparts");
restart_write_blocks(s->sparts, s->nr_sparts, sizeof(struct spart), stream,
"sparts");
}
/**
......@@ -3299,15 +3303,18 @@ void space_struct_restore(struct space *s, FILE *stream) {
s->size_parts * sizeof(struct xpart)) != 0)
error("Failed to allocate restore xpart array.");
restart_read_blocks(s->parts, s->nr_parts, sizeof(struct part), stream, "parts");
restart_read_blocks(s->xparts, s->nr_parts, sizeof(struct xpart), stream, "xparts");
restart_read_blocks(s->parts, s->nr_parts, sizeof(struct part), stream,
"parts");
restart_read_blocks(s->xparts, s->nr_parts, sizeof(struct xpart), stream,
"xparts");
}
if (s->nr_gparts > 0) {
if (posix_memalign((void *)&s->gparts, gpart_align,
s->size_gparts * sizeof(struct gpart)) != 0)
error("Failed to allocate restore gpart array.");
restart_read_blocks(s->gparts, s->nr_gparts, sizeof(struct gpart), stream, "gparts");
restart_read_blocks(s->gparts, s->nr_gparts, sizeof(struct gpart), stream,
"gparts");
}
if (s->nr_sparts > 0) {
......@@ -3315,10 +3322,10 @@ void space_struct_restore(struct space *s, FILE *stream) {
s->size_sparts * sizeof(struct spart)) != 0)
error("Failed to allocate restore spart array.");
restart_read_blocks(s->sparts, s->nr_sparts, sizeof(struct spart), stream, "sparts");
restart_read_blocks(s->sparts, s->nr_sparts, sizeof(struct spart), stream,
"sparts");
}
/* XXX need to reconnect the gravity parts to their hydro and star particles. XXX */
/* XXX need to reconnect the gravity parts to their hydro and star particles.
* XXX */
}
......@@ -240,5 +240,4 @@ void space_free_cells(struct space *s);
void space_struct_dump(struct space *s, FILE *stream);
void space_struct_restore(struct space *s, FILE *stream);
#endif /* SWIFT_SPACE_H */
......@@ -604,26 +604,24 @@ void units_print(const struct unit_system* us) {
message("\tUnit Temperature: %g", us->UnitTemperature_in_cgs);
}
/**
* @brief Write a units struct to the given FILE as a stream of bytes.
*
* @param us the units
* @param stream the file stream
*/
void units_struct_dump(const struct unit_system *us, FILE *stream) {
restart_write_blocks((void *)us, sizeof(struct unit_system), 1, stream,
void units_struct_dump(const struct unit_system* us, FILE* stream) {
restart_write_blocks((void*)us, sizeof(struct unit_system), 1, stream,
"units");
}
/**
* @brief Restore a units struct from the given FILE as a stream of bytes.
*
* @param us the units
* @param stream the file stream
*/
void units_struct_restore(const struct unit_system *us, FILE *stream) {
restart_read_blocks((void *)us, sizeof(struct unit_system), 1, stream,
void units_struct_restore(const struct unit_system* us, FILE* stream) {
restart_read_blocks((void*)us, sizeof(struct unit_system), 1, stream,
"units");
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment