Skip to content

Commit

Permalink
Allow setting location of filters through an environment variable (MR…
Browse files Browse the repository at this point in the history
…ChemSoft#180)

* Log location of filters

* Fix warning

* Abort if filter paths not set

* More debug info

* Abort if no filters folder is set

* Pass more search paths for filter files

* Remove code duplication in finding filter files

Also search in MWFILTERS_DIR, specifiable as environment variable

* Clean up MWFilter.cpp from debug prints

* Remove debug printing from details.cpp
  • Loading branch information
robertodr authored Oct 11, 2021
1 parent dcbad5b commit 3e9ffef
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 29 deletions.
7 changes: 1 addition & 6 deletions src/core/CrossCorrelation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,7 @@ CrossCorrelation::CrossCorrelation(int k, int t)
MSG_ERROR("Unknown filter type: " << this->type);
}

for (auto n : {mwfilters_source_dir(), mwfilters_install_dir()}) {
if (details::directory_exists(n)) {
setCCCPaths(n);
break;
}
}
setCCCPaths(details::find_filters());

readCCCBin();
}
Expand Down
7 changes: 1 addition & 6 deletions src/core/MWFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,7 @@ MWFilter::MWFilter(int k, int t)
MSG_ERROR("Unknown filter type: " << this->type);
}

for (auto n : {mwfilters_source_dir(), mwfilters_install_dir()}) {
if (details::directory_exists(n)) {
setFilterPaths(n);
break;
}
}
setFilterPaths(details::find_filters());

generateBlocks();

Expand Down
8 changes: 1 addition & 7 deletions src/treebuilders/BSCalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,7 @@ BSCalculator::BSCalculator(const ScalingBasis &basis, int n)

void BSCalculator::readSMatrix(const ScalingBasis &basis, char n) {
std::string file;
std::string path;
for (auto l : {mwfilters_source_dir(), mwfilters_install_dir()}) {
if (details::directory_exists(l)) {
path = l;
break;
}
}
std::string path = details::find_filters();

if (basis.getScalingType() == Legendre) file = path + "/L_b-spline-deriv" + n + ".txt";
if (basis.getScalingType() == Interpol) file = path + "/I_b-spline-deriv" + n + ".txt";
Expand Down
2 changes: 1 addition & 1 deletion src/treebuilders/ConvolutionCalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ template <int D> void ConvolutionCalculator<D>::touchParentNodes(MWTree<D> &tree
auto car_prod = math_utils::cartesian_product(std::vector<int>{-1, 0}, D);
for (auto i = -1; i > oper_scale - 1; i--) {
for (auto &a : car_prod) {
std::array<int, D> l;
std::array<int, D> l{};
std::copy_n(a.begin(), D, l.begin());
NodeIndex<D> idx(i, l);
tree.getNode(idx);
Expand Down
9 changes: 2 additions & 7 deletions src/treebuilders/PHCalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,8 @@ PHCalculator::PHCalculator(const ScalingBasis &basis, int n)

void PHCalculator::readSMatrix(const ScalingBasis &basis, char n) {
std::string file;
std::string path;
for (auto l : {mwfilters_source_dir(), mwfilters_install_dir()}) {
if (details::directory_exists(l)) {
path = l;
break;
}
}
std::string path = details::find_filters();

if (basis.getScalingType() == Legendre) file = path + "/L_ph_deriv_" + n + ".txt";
if (basis.getScalingType() == Interpol) file = path + "/I_ph_deriv_" + n + ".txt";
if (basis.getScalingOrder() < 0) MSG_ABORT("Scaling order not supported");
Expand Down
4 changes: 2 additions & 2 deletions src/trees/NodeIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ template <int D> class NodeIndex final {
}

private:
short int N; ///< Length scale index 2^N
std::array<int, D> L; ///< Translation index [x,y,z,...]
short int N{0}; ///< Length scale index 2^N
std::array<int, D> L{}; ///< Translation index [x,y,z,...]
};

/** @brief ostream printer */
Expand Down
20 changes: 20 additions & 0 deletions src/utils/details.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@

#include <algorithm>
#include <array>
#include <cstdlib>
#include <string>
#include <sys/stat.h>
#include <sys/types.h>

#include "MRCPP/config.h"
#include "utils/Printer.h"

namespace mrcpp {
Expand All @@ -48,6 +50,24 @@ bool directory_exists(std::string path) {
return (info.st_mode & S_IFDIR) ? true : false;
}

std::string find_filters() {
std::string filters;
auto envvar = "";
if (const char *env_p = std::getenv("MWFILTERS_DIR")) envvar = env_p;
for (auto n : {envvar, mwfilters_source_dir(), mwfilters_install_dir()}) {
if (details::directory_exists(n)) {
filters = n;
break;
}
}

if (filters.empty()) {
MSG_ABORT("Could not find a folder containing filters!");
} else {
return filters;
}
}

// helper function: parse a string and returns the nth integer number
int get_val(char *line, int n) {
char *p = line;
Expand Down
1 change: 1 addition & 0 deletions src/utils/details.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
namespace mrcpp {
namespace details {
bool directory_exists(std::string path);
std::string find_filters();
int get_memory_usage();
template <int D> bool are_all_equal(const std::array<double, D> &exponent);
template <typename T, size_t D> bool are_any(const std::array<T, D> &col, const T eq) {
Expand Down

0 comments on commit 3e9ffef

Please sign in to comment.