From c76abcbbbec09e675e270d9eef3f3e331c951377 Mon Sep 17 00:00:00 2001 From: Lukas Winkler Date: Mon, 7 Oct 2024 19:08:59 +0200 Subject: [PATCH] name input_powerspec.txt after config file --- src/config_file.hh | 10 ++++++++++ src/convolution_kernel.cc | 2 +- src/transfer_function.hh | 4 ++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/config_file.hh b/src/config_file.hh index 891cc97..f27d2c8 100644 --- a/src/config_file.hh +++ b/src/config_file.hh @@ -161,6 +161,10 @@ public: } items_[in_section + '/' + name] = value; + + size_t lastindex = filename.find_last_of('.'); + std::string config_basename = filename.substr(0, lastindex); + items_["meta/config_basename"] = config_basename; } } @@ -288,6 +292,12 @@ public: return get_value_safe("", key, default_value); } + std::string get_path_relative_to_config(std::string const &filename) const { + std::string empty_string; + const std::string basename = get_value_safe("meta", "config_basename", empty_string); + return basename + "_" + filename; + } + //! dumps all key-value pairs to a std::ostream void dump(std::ostream &out) { std::map::const_iterator i = items_.begin(); diff --git a/src/convolution_kernel.cc b/src/convolution_kernel.cc index 4a4efc9..c9a37c3 100644 --- a/src/convolution_kernel.cc +++ b/src/convolution_kernel.cc @@ -177,7 +177,7 @@ class kernel_k : public kernel pnorm_ = ptf->cosmo_params_["pnorm"]; kfac_ = 2.0 * M_PI / boxlength_; kmax_ = kfac_ / 2; - tfk_ = new TransferFunction_k(type_, ptf_, nspec_, pnorm_); + tfk_ = new TransferFunction_k(type_, ptf_, nspec_, pnorm_, cf); cparam_.nx = 1; cparam_.ny = 1; diff --git a/src/transfer_function.hh b/src/transfer_function.hh index 2e4efaf..a713b5d 100644 --- a/src/transfer_function.hh +++ b/src/transfer_function.hh @@ -163,7 +163,7 @@ public: double pnorm_, sqrtpnorm_; static tf_type type_; - TransferFunction_k(tf_type type, transfer_function *tf, real_t nspec, real_t pnorm) + TransferFunction_k(tf_type type, transfer_function *tf, real_t nspec, real_t pnorm, config_file &cf) : pnorm_(pnorm) { ptf_ = tf; @@ -171,7 +171,7 @@ public: sqrtpnorm_ = sqrt(pnorm_); type_ = type; - std::string fname("input_powerspec.txt"); + std::string fname(cf.get_path_relative_to_config("input_powerspec.txt")); if (type == delta_cdm || type == delta_matter) { std::ofstream ofs(fname.c_str());