From 40ec350d2c1e813a5b58589e55992cbb63cbf724 Mon Sep 17 00:00:00 2001 From: lhausamm <loic_hausammann@hotmail.com> Date: Thu, 14 Jun 2018 16:54:22 +0200 Subject: [PATCH] Remove const from params --- src/cosmology.c | 2 +- src/cosmology.h | 2 +- src/engine.c | 4 +-- src/engine.h | 6 ++-- src/gravity_properties.c | 2 +- src/gravity_properties.h | 2 +- src/hydro_properties.c | 2 +- src/hydro_properties.h | 2 +- src/parallel_io.c | 4 +-- src/parser.c | 72 ++++++++++++++++++---------------------- src/parser.h | 20 +++++------ src/partition.c | 2 +- src/partition.h | 2 +- src/physical_constants.c | 2 +- src/physical_constants.h | 2 +- src/serial_io.c | 2 +- src/single_io.c | 2 +- src/space.c | 2 +- src/space.h | 2 +- src/units.c | 4 +-- src/units.h | 4 +-- 21 files changed, 67 insertions(+), 75 deletions(-) diff --git a/src/cosmology.c b/src/cosmology.c index 4da9528784..0cc528c8a0 100644 --- a/src/cosmology.c +++ b/src/cosmology.c @@ -387,7 +387,7 @@ void cosmology_init_tables(struct cosmology *c) { * @param phys_const The physical constants in the current system of units. * @param c The #cosmology to initialise. */ -void cosmology_init(const struct swift_params *params, +void cosmology_init(struct swift_params *params, const struct unit_system *us, const struct phys_const *phys_const, struct cosmology *c) { diff --git a/src/cosmology.h b/src/cosmology.h index 109b80a57d..93751fba6f 100644 --- a/src/cosmology.h +++ b/src/cosmology.h @@ -181,7 +181,7 @@ double cosmology_get_therm_kick_factor(const struct cosmology *cosmo, double cosmology_get_delta_time(const struct cosmology *c, double a1, double a2); -void cosmology_init(const struct swift_params *params, +void cosmology_init(struct swift_params *params, const struct unit_system *us, const struct phys_const *phys_const, struct cosmology *c); diff --git a/src/engine.c b/src/engine.c index 14c9199757..c62feb434d 100644 --- a/src/engine.c +++ b/src/engine.c @@ -5422,7 +5422,7 @@ void engine_unpin(void) { * @param sourceterms The properties of the source terms function. */ void engine_init(struct engine *e, struct space *s, - const struct swift_params *params, long long Ngas, + struct swift_params *params, long long Ngas, long long Ngparts, long long Nstars, int policy, int verbose, struct repartition *reparttype, const struct unit_system *internal_units, @@ -5553,7 +5553,7 @@ void engine_init(struct engine *e, struct space *s, * @param restart_file The name of our restart file. */ void engine_config(int restart, struct engine *e, - const struct swift_params *params, int nr_nodes, int nodeID, + struct swift_params *params, int nr_nodes, int nodeID, int nr_threads, int with_aff, int verbose, const char *restart_file) { diff --git a/src/engine.h b/src/engine.h index c376434c7f..877dbf3627 100644 --- a/src/engine.h +++ b/src/engine.h @@ -315,7 +315,7 @@ struct engine { struct sourceterms *sourceterms; /* The (parsed) parameter file */ - const struct swift_params *parameter_file; + struct swift_params *parameter_file; /* Temporary struct to hold a group of deferable properties (in MPI mode * these are reduced together, but may not be required just yet). */ @@ -355,7 +355,7 @@ void engine_reconstruct_multipoles(struct engine *e); void engine_print_stats(struct engine *e); void engine_dump_snapshot(struct engine *e); void engine_init(struct engine *e, struct space *s, - const struct swift_params *params, long long Ngas, + struct swift_params *params, long long Ngas, long long Ngparts, long long Nstars, int policy, int verbose, struct repartition *reparttype, const struct unit_system *internal_units, @@ -367,7 +367,7 @@ void engine_init(struct engine *e, struct space *s, const struct chemistry_global_data *chemistry, struct sourceterms *sourceterms); void engine_config(int restart, struct engine *e, - const struct swift_params *params, int nr_nodes, int nodeID, + struct swift_params *params, int nr_nodes, int nodeID, int nr_threads, int with_aff, int verbose, const char *restart_file); void engine_launch(struct engine *e); diff --git a/src/gravity_properties.c b/src/gravity_properties.c index afebc60435..05e28dc860 100644 --- a/src/gravity_properties.c +++ b/src/gravity_properties.c @@ -38,7 +38,7 @@ #define gravity_props_default_rebuild_frequency 0.01f void gravity_props_init(struct gravity_props *p, - const struct swift_params *params, + struct swift_params *params, const struct cosmology *cosmo) { /* Tree updates */ diff --git a/src/gravity_properties.h b/src/gravity_properties.h index 418e74e715..6f0898a164 100644 --- a/src/gravity_properties.h +++ b/src/gravity_properties.h @@ -83,7 +83,7 @@ struct gravity_props { void gravity_props_print(const struct gravity_props *p); void gravity_props_init(struct gravity_props *p, - const struct swift_params *params, + struct swift_params *params, const struct cosmology *cosmo); void gravity_update(struct gravity_props *p, const struct cosmology *cosmo); diff --git a/src/hydro_properties.c b/src/hydro_properties.c index e63679eaad..c5448f7735 100644 --- a/src/hydro_properties.c +++ b/src/hydro_properties.c @@ -52,7 +52,7 @@ void hydro_props_init(struct hydro_props *p, const struct phys_const *phys_const, const struct unit_system *us, - const struct swift_params *params) { + struct swift_params *params) { /* Kernel properties */ p->eta_neighbours = parser_get_param_float(params, "SPH:resolution_eta"); diff --git a/src/hydro_properties.h b/src/hydro_properties.h index 2799f6c86e..64a840692d 100644 --- a/src/hydro_properties.h +++ b/src/hydro_properties.h @@ -86,7 +86,7 @@ void hydro_props_print(const struct hydro_props *p); void hydro_props_init(struct hydro_props *p, const struct phys_const *phys_const, const struct unit_system *us, - const struct swift_params *params); + struct swift_params *params); #if defined(HAVE_HDF5) void hydro_props_print_snapshot(hid_t h_grpsph, const struct hydro_props *p); diff --git a/src/parallel_io.c b/src/parallel_io.c index 69093eb48e..039cb85bae 100644 --- a/src/parallel_io.c +++ b/src/parallel_io.c @@ -890,7 +890,7 @@ void prepare_file(struct engine* e, const char* baseName, long long N_total[6], const struct xpart* xparts = e->s->xparts; const struct gpart* gparts = e->s->gparts; const struct spart* sparts = e->s->sparts; - const struct swift_params* params = e->parameter_file; + struct swift_params* params = e->parameter_file; FILE* xmfFile = 0; int periodic = e->s->periodic; int numFiles = 1; @@ -1141,7 +1141,7 @@ void write_output_parallel(struct engine* e, const char* baseName, struct gpart* dmparts = NULL; const struct spart* sparts = e->s->sparts; const struct cooling_function_data* cooling = e->cooling_func; - const struct swift_params* params = e->parameter_file; + struct swift_params* params = e->parameter_file; /* Number of unassociated gparts */ const size_t Ndm = Ntot > 0 ? Ntot - (Ngas + Nstars) : 0; diff --git a/src/parser.c b/src/parser.c index 5f789df45a..78fea7b626 100644 --- a/src/parser.c +++ b/src/parser.c @@ -444,11 +444,10 @@ static void parse_section_param(char *line, int *isFirstParam, * @param name Name of the parameter to be found * @return Value of the parameter found */ -int parser_get_param_int(const struct swift_params *params, const char *name) { +int parser_get_param_int(struct swift_params *params, const char *name) { char str[PARSER_MAX_LINE_SIZE]; int retParam = 0; - struct swift_params *tmp = (struct swift_params*) params; for (int i = 0; i < params->paramCount; i++) { if (!strcmp(name, params->data[i].name)) { @@ -461,7 +460,7 @@ int parser_get_param_int(const struct swift_params *params, const char *name) { } /* this parameter has been used */ - tmp->data[i].used = 1; + params->data[i].used = 1; return retParam; } @@ -479,12 +478,11 @@ int parser_get_param_int(const struct swift_params *params, const char *name) { * @param name Name of the parameter to be found * @return Value of the parameter found */ -char parser_get_param_char(const struct swift_params *params, +char parser_get_param_char(struct swift_params *params, const char *name) { char str[PARSER_MAX_LINE_SIZE]; char retParam = 0; - struct swift_params *tmp = (struct swift_params*) params; for (int i = 0; i < params->paramCount; i++) { if (!strcmp(name, params->data[i].name)) { @@ -497,7 +495,7 @@ char parser_get_param_char(const struct swift_params *params, } /* this parameter has been used */ - tmp->data[i].used = 1; + params->data[i].used = 1; return retParam; } @@ -515,12 +513,11 @@ char parser_get_param_char(const struct swift_params *params, * @param name Name of the parameter to be found * @return Value of the parameter found */ -float parser_get_param_float(const struct swift_params *params, +float parser_get_param_float(struct swift_params *params, const char *name) { char str[PARSER_MAX_LINE_SIZE]; float retParam = 0.f; - struct swift_params *tmp = (struct swift_params*) params; for (int i = 0; i < params->paramCount; i++) { if (!strcmp(name, params->data[i].name)) { @@ -533,7 +530,7 @@ float parser_get_param_float(const struct swift_params *params, } /* this parameter has been used */ - tmp->data[i].used = 1; + params->data[i].used = 1; return retParam; } @@ -551,12 +548,11 @@ float parser_get_param_float(const struct swift_params *params, * @param name Name of the parameter to be found * @return Value of the parameter found */ -double parser_get_param_double(const struct swift_params *params, +double parser_get_param_double(struct swift_params *params, const char *name) { char str[PARSER_MAX_LINE_SIZE]; double retParam = 0.; - struct swift_params *tmp = (struct swift_params*) params; for (int i = 0; i < params->paramCount; i++) { if (!strcmp(name, params->data[i].name)) { @@ -569,7 +565,7 @@ double parser_get_param_double(const struct swift_params *params, } /* this parameter has been used */ - tmp->data[i].used = 1; + params->data[i].used = 1; return retParam; } @@ -587,14 +583,14 @@ double parser_get_param_double(const struct swift_params *params, * @param name Name of the parameter to be found * @param retParam (return) Value of the parameter found */ -void parser_get_param_string(const struct swift_params *params, +void parser_get_param_string(struct swift_params *params, const char *name, char *retParam) { - struct swift_params *tmp = (struct swift_params*) params; + for (int i = 0; i < params->paramCount; i++) { if (!strcmp(name, params->data[i].name)) { strcpy(retParam, params->data[i].value); /* this parameter has been used */ - tmp->data[i].used = 1; + params->data[i].used = 1; return; } } @@ -610,12 +606,11 @@ void parser_get_param_string(const struct swift_params *params, * @param def Default value of the parameter of not found. * @return Value of the parameter found */ -int parser_get_opt_param_int(const struct swift_params *params, +int parser_get_opt_param_int(struct swift_params *params, const char *name, int def) { char str[PARSER_MAX_LINE_SIZE]; int retParam = 0; - struct swift_params *tmp = (struct swift_params*) params; for (int i = 0; i < params->paramCount; i++) { if (!strcmp(name, params->data[i].name)) { @@ -628,7 +623,7 @@ int parser_get_opt_param_int(const struct swift_params *params, } /* this parameter has been used */ - tmp->data[i].used = 1; + params->data[i].used = 1; return retParam; } @@ -638,10 +633,10 @@ int parser_get_opt_param_int(const struct swift_params *params, sprintf(str, "%s: %i", name, def); /* Add it to params */ - parser_set_param(tmp, str); + parser_set_param(params, str); /* Set parameter as used */ - tmp->data[params->paramCount-1].used = 1; + params->data[params->paramCount-1].used = 1; return def; } @@ -654,12 +649,11 @@ int parser_get_opt_param_int(const struct swift_params *params, * @param def Default value of the parameter of not found. * @return Value of the parameter found */ -char parser_get_opt_param_char(const struct swift_params *params, +char parser_get_opt_param_char(struct swift_params *params, const char *name, char def) { char str[PARSER_MAX_LINE_SIZE]; char retParam = 0; - struct swift_params *tmp = (struct swift_params*) params; for (int i = 0; i < params->paramCount; i++) { if (!strcmp(name, params->data[i].name)) { @@ -672,7 +666,7 @@ char parser_get_opt_param_char(const struct swift_params *params, } /* this parameter has been used */ - tmp->data[i].used = 1; + params->data[i].used = 1; return retParam; } @@ -682,10 +676,10 @@ char parser_get_opt_param_char(const struct swift_params *params, sprintf(str, "%s: %c", name, def); /* Add it to params */ - parser_set_param(tmp, str); + parser_set_param(params, str); /* Set parameter as used */ - tmp->data[params->paramCount-1].used = 1; + params->data[params->paramCount-1].used = 1; return def; } @@ -698,12 +692,11 @@ char parser_get_opt_param_char(const struct swift_params *params, * @param def Default value of the parameter of not found. * @return Value of the parameter found */ -float parser_get_opt_param_float(const struct swift_params *params, +float parser_get_opt_param_float(struct swift_params *params, const char *name, float def) { char str[PARSER_MAX_LINE_SIZE]; float retParam = 0.f; - struct swift_params *tmp = (struct swift_params*) params; for (int i = 0; i < params->paramCount; i++) { if (!strcmp(name, params->data[i].name)) { @@ -716,7 +709,7 @@ float parser_get_opt_param_float(const struct swift_params *params, } /* this parameter has been used */ - tmp->data[i].used = 1; + params->data[i].used = 1; return retParam; } @@ -726,10 +719,10 @@ float parser_get_opt_param_float(const struct swift_params *params, sprintf(str, "%s: %f", name, def); /* Add it to params */ - parser_set_param(tmp, str); + parser_set_param(params, str); /* Set parameter as used */ - tmp->data[params->paramCount-1].used = 1; + params->data[params->paramCount-1].used = 1; return def; } @@ -742,12 +735,11 @@ float parser_get_opt_param_float(const struct swift_params *params, * @param def Default value of the parameter of not found. * @return Value of the parameter found */ -double parser_get_opt_param_double(const struct swift_params *params, +double parser_get_opt_param_double(struct swift_params *params, const char *name, double def) { char str[PARSER_MAX_LINE_SIZE]; double retParam = 0.; - struct swift_params *tmp = (struct swift_params*) params; for (int i = 0; i < params->paramCount; i++) { if (!strcmp(name, params->data[i].name)) { @@ -760,7 +752,7 @@ double parser_get_opt_param_double(const struct swift_params *params, } /* this parameter has been used */ - tmp->data[i].used = 1; + params->data[i].used = 1; return retParam; } @@ -770,10 +762,10 @@ double parser_get_opt_param_double(const struct swift_params *params, sprintf(str, "%s: %lf", name, def); /* Add it to params */ - parser_set_param(tmp, str); + parser_set_param(params, str); /* Set parameter as used */ - tmp->data[params->paramCount-1].used = 1; + params->data[params->paramCount-1].used = 1; return def; } @@ -786,16 +778,16 @@ double parser_get_opt_param_double(const struct swift_params *params, * @param def Default value of the parameter of not found. * @param retParam (return) Value of the parameter found */ -void parser_get_opt_param_string(const struct swift_params *params, +void parser_get_opt_param_string(struct swift_params *params, const char *name, char *retParam, const char *def) { - struct swift_params *tmp = (struct swift_params*) params; + for (int i = 0; i < params->paramCount; i++) { if (!strcmp(name, params->data[i].name)) { strcpy(retParam, params->data[i].value); /* this parameter has been used */ - tmp->data[i].used = 1; + params->data[i].used = 1; return; } @@ -806,10 +798,10 @@ void parser_get_opt_param_string(const struct swift_params *params, sprintf(str, "%s: %s", name, def); /* Add it to params */ - parser_set_param(tmp, str); + parser_set_param(params, str); /* Set parameter as used */ - tmp->data[params->paramCount-1].used = 1; + params->data[params->paramCount-1].used = 1; strcpy(retParam, def); } diff --git a/src/parser.h b/src/parser.h index b29454d50f..a45fc381e2 100644 --- a/src/parser.h +++ b/src/parser.h @@ -64,24 +64,24 @@ void parser_write_params_to_file(const struct swift_params *params, int write_all); void parser_set_param(struct swift_params *params, const char *desc); -char parser_get_param_char(const struct swift_params *params, const char *name); -int parser_get_param_int(const struct swift_params *params, const char *name); -float parser_get_param_float(const struct swift_params *params, +char parser_get_param_char(struct swift_params *params, const char *name); +int parser_get_param_int(struct swift_params *params, const char *name); +float parser_get_param_float(struct swift_params *params, const char *name); -double parser_get_param_double(const struct swift_params *params, +double parser_get_param_double(struct swift_params *params, const char *name); -void parser_get_param_string(const struct swift_params *params, +void parser_get_param_string(struct swift_params *params, const char *name, char *retParam); -char parser_get_opt_param_char(const struct swift_params *params, +char parser_get_opt_param_char(struct swift_params *params, const char *name, char def); -int parser_get_opt_param_int(const struct swift_params *params, +int parser_get_opt_param_int(struct swift_params *params, const char *name, int def); -float parser_get_opt_param_float(const struct swift_params *params, +float parser_get_opt_param_float(struct swift_params *params, const char *name, float def); -double parser_get_opt_param_double(const struct swift_params *params, +double parser_get_opt_param_double(struct swift_params *params, const char *name, double def); -void parser_get_opt_param_string(const struct swift_params *params, +void parser_get_opt_param_string(struct swift_params *params, const char *name, char *retParam, const char *def); diff --git a/src/partition.c b/src/partition.c index 8feae3b7a8..85a51dddf2 100644 --- a/src/partition.c +++ b/src/partition.c @@ -1041,7 +1041,7 @@ void partition_initial_partition(struct partition *initial_partition, */ void partition_init(struct partition *partition, struct repartition *repartition, - const struct swift_params *params, int nr_nodes) { + struct swift_params *params, int nr_nodes) { #ifdef WITH_MPI diff --git a/src/partition.h b/src/partition.h index 3ad479c6b1..ec7d670a43 100644 --- a/src/partition.h +++ b/src/partition.h @@ -76,7 +76,7 @@ int partition_space_to_space(double *oldh, double *oldcdim, int *oldnodeID, struct space *s); void partition_init(struct partition *partition, struct repartition *repartition, - const struct swift_params *params, int nr_nodes); + struct swift_params *params, int nr_nodes); /* Dump/restore. */ void partition_store_celllist(struct space *s, struct repartition *reparttype); diff --git a/src/physical_constants.c b/src/physical_constants.c index b1dbeaeecf..b0f0df7745 100644 --- a/src/physical_constants.c +++ b/src/physical_constants.c @@ -39,7 +39,7 @@ * @param internal_const The physical constants to initialize. */ void phys_const_init(const struct unit_system *us, - const struct swift_params *params, + struct swift_params *params, struct phys_const *internal_const) { /* Units are declared as {U_M, U_L, U_t, U_I, U_T} */ diff --git a/src/physical_constants.h b/src/physical_constants.h index b0f929632b..75b79bc0a5 100644 --- a/src/physical_constants.h +++ b/src/physical_constants.h @@ -90,7 +90,7 @@ struct phys_const { }; void phys_const_init(const struct unit_system* us, - const struct swift_params* params, + struct swift_params* params, struct phys_const* internal_const); void phys_const_print(const struct phys_const* internal_const); diff --git a/src/serial_io.c b/src/serial_io.c index f7ea4fa110..a87495c935 100644 --- a/src/serial_io.c +++ b/src/serial_io.c @@ -733,7 +733,7 @@ void write_output_serial(struct engine* e, const char* baseName, struct gpart* dmparts = NULL; const struct spart* sparts = e->s->sparts; const struct cooling_function_data* cooling = e->cooling_func; - const struct swift_params* params = e->parameter_file; + struct swift_params* params = e->parameter_file; FILE* xmfFile = 0; /* Number of unassociated gparts */ diff --git a/src/single_io.c b/src/single_io.c index 4255cd52bf..58ae7b97b9 100644 --- a/src/single_io.c +++ b/src/single_io.c @@ -600,7 +600,7 @@ void write_output_single(struct engine* e, const char* baseName, struct gpart* dmparts = NULL; const struct spart* sparts = e->s->sparts; const struct cooling_function_data* cooling = e->cooling_func; - const struct swift_params* params = e->parameter_file; + struct swift_params* params = e->parameter_file; /* Number of unassociated gparts */ const size_t Ndm = Ntot > 0 ? Ntot - (Ngas + Nstars) : 0; diff --git a/src/space.c b/src/space.c index 3efb1080c3..83b6707107 100644 --- a/src/space.c +++ b/src/space.c @@ -2641,7 +2641,7 @@ void space_convert_quantities(struct space *s, int verbose) { * parts with a cutoff below half the cell width are then split * recursively. */ -void space_init(struct space *s, const struct swift_params *params, +void space_init(struct space *s, struct swift_params *params, const struct cosmology *cosmo, double dim[3], struct part *parts, struct gpart *gparts, struct spart *sparts, size_t Npart, size_t Ngpart, size_t Nspart, int periodic, diff --git a/src/space.h b/src/space.h index 75d6b7b113..67fc34e55b 100644 --- a/src/space.h +++ b/src/space.h @@ -200,7 +200,7 @@ void space_gparts_sort(struct gpart *gparts, struct part *parts, void space_sparts_sort(struct spart *sparts, int *ind, int *counts, int num_bins, ptrdiff_t sparts_offset); void space_getcells(struct space *s, int nr_cells, struct cell **cells); -void space_init(struct space *s, const struct swift_params *params, +void space_init(struct space *s, struct swift_params *params, const struct cosmology *cosmo, double dim[3], struct part *parts, struct gpart *gparts, struct spart *sparts, size_t Npart, size_t Ngpart, size_t Nspart, int periodic, diff --git a/src/units.c b/src/units.c index ae33b0c263..af11d7de40 100644 --- a/src/units.c +++ b/src/units.c @@ -78,7 +78,7 @@ void units_init(struct unit_system* us, double U_M_in_cgs, double U_L_in_cgs, * @param category The section of the parameter file to read from. */ void units_init_from_params(struct unit_system* us, - const struct swift_params* params, + struct swift_params* params, const char* category) { char buffer[200]; @@ -105,7 +105,7 @@ void units_init_from_params(struct unit_system* us, * @param def The default unit system to copy from if required. */ void units_init_default(struct unit_system* us, - const struct swift_params* params, const char* category, + struct swift_params* params, const char* category, const struct unit_system* def) { if (!def) error("Default unit_system not allocated"); diff --git a/src/units.h b/src/units.h index a6169d0a2f..1f0ef3cbd7 100644 --- a/src/units.h +++ b/src/units.h @@ -98,10 +98,10 @@ enum unit_conversion_factor { void units_init_cgs(struct unit_system*); void units_init(struct unit_system* us, double U_M_in_cgs, double U_L_in_cgs, double U_t_in_cgs, double U_C_in_cgs, double U_T_in_cgs); -void units_init_from_params(struct unit_system*, const struct swift_params*, +void units_init_from_params(struct unit_system*, struct swift_params*, const char* category); void units_init_default(struct unit_system* us, - const struct swift_params* params, const char* category, + struct swift_params* params, const char* category, const struct unit_system* def); int units_are_equal(const struct unit_system* a, const struct unit_system* b); -- GitLab