Skip to content

Commit

Permalink
remove hardcoding of radiation filenames and number of files -- requi…
Browse files Browse the repository at this point in the history
…res > C++ 17
  • Loading branch information
Jeffrey Reep committed Jul 3, 2024
1 parent 1bf1db7 commit 9f3d71b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ AddOption('--linkflags', dest='linkflags', type='string', nargs=1, action='store


subdirs = ['source']
cxx_flags = ['-std=c++14',]
cxx_flags = ['-std=c++17',]
try:
CXX = os.environ['CXX']
except KeyError:
Expand Down
5 changes: 5 additions & 0 deletions source/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ General purpose includes to be used everywhere
#include <string>
#include <vector>
#include <limits>
#include <filesystem>
#include <set>
#include "boost/array.hpp"
#include "util/xmlreader.h"

namespace fs = std::filesystem;


// Structure to hold all input parameters
struct Parameters {
/* Total simulation time (in s) */
Expand Down
25 changes: 20 additions & 5 deletions source/loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,17 +550,32 @@ void Loop::ReadRadiativeLossData()
{
// Reads in the radiative loss files. Only need to do once during the setup.
std::string path = "data/radiation/";
std::string filenames[] = {"abund_10_rad_loss.dat","abund_15_rad_loss.dat","abund_20_rad_loss.dat","abund_25_rad_loss.dat",
"abund_30_rad_loss.dat","abund_35_rad_loss.dat","abund_40_rad_loss.dat"};
std::vector<std::string> filenames;
std::ifstream fin;
int n_files = sizeof(filenames)/sizeof(filenames[0]);
std::string filename;

/* We use a set here to read in the filenames because each filename is unique,
* and this will therefore sort automatically. */
std::set<fs::path> file_set;

// Read in the filenames of each file in the radiation directory:
for (const auto & entry : fs::directory_iterator(path))
{
file_set.insert(entry.path());
}
for (auto &file : file_set)
{
filenames.push_back(file.c_str());
}
int n_abund = filenames.size();

double number;
char comma;

for (int i=0; i < n_files; ++i) // Loop over files for different abundances
for (int i=0; i < n_abund; ++i) // Loop over files for different abundances
{
fin.open(path+filenames[i]);
//fin.open(path+filenames[i]);
fin.open(filenames[i]);

for (int j=0; j < 100; ++j) // Loop over temperatures (rows in files)
{
Expand Down

0 comments on commit 9f3d71b

Please sign in to comment.