Skip to content

Commit

Permalink
Merge pull request #5 from cosmo-sims/output-filenames
Browse files Browse the repository at this point in the history
name output files after config and write output log
  • Loading branch information
ohahn authored Jul 18, 2024
2 parents a19b967 + 41a0e34 commit eb5667c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
9 changes: 9 additions & 0 deletions include/config_file.hh
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ 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;
}

//! inserts a key/value pair in the hash map
Expand Down Expand Up @@ -288,6 +291,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<std::string, std::string>::const_iterator i = items_.begin();
Expand Down
6 changes: 3 additions & 3 deletions src/ic_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ int run( config_file& the_config )
const real_t astart = 1.0/(1.0+zstart);
const real_t volfac(std::pow(boxlen / ngrid / 2.0 / M_PI, 1.5));

the_cosmo_calc->write_powerspectrum(astart, "input_powerspec.txt" );
the_cosmo_calc->write_transfer("input_transfer.txt" );
the_cosmo_calc->write_powerspectrum(astart, the_config.get_path_relative_to_config("input_powerspec.txt"));
the_cosmo_calc->write_transfer(the_config.get_path_relative_to_config("input_transfer.txt"));

// the_cosmo_calc->compute_sigma_bc();
// abort();
Expand Down Expand Up @@ -763,7 +763,7 @@ int run( config_file& the_config )
}, psi);

the_output_plugin->write_grid_data( rho, this_species, fluid_component::density );
rho.Write_PowerSpectrum("input_powerspec_sampled_evolved_semiclassical.txt");
rho.Write_PowerSpectrum(the_config.get_path_relative_to_config("input_powerspec_sampled_evolved_semiclassical.txt"));
rho.FourierTransformBackward();

//======================================================================
Expand Down
6 changes: 6 additions & 0 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ int main( int argc, char** argv )

// open the configuration file
config_file the_config(argv[1]);
std::string log_filename = the_config.get_path_relative_to_config("log.txt");
music::logger::set_output(log_filename);
music::ilog << " argv[1] : " << argv[1] << std::endl;
music::ilog << " config_basename : " << the_config.get_path_relative_to_config("") << std::endl;
music::ilog << " log file : " << log_filename << std::endl;
music::ilog << "-------------------------------------------------------------------------------" << std::endl;

//------------------------------------------------------------------------------
// Set up FFTW
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/transfer_CLASS.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class transfer_CLASS_plugin : public TransferFunction_plugin
{
this->tf_isnormalised_ = true;

ofs_class_input_.open("input_class_parameters.ini", std::ios::trunc);
ofs_class_input_.open(cf.get_path_relative_to_config("input_class_parameters.ini"), std::ios::trunc);

// all cosmological parameters need to be passed through the_cosmo_calc

Expand Down

0 comments on commit eb5667c

Please sign in to comment.