Skip to content

Commit

Permalink
Added option to read in vectors of ints and bools from input file, to…
Browse files Browse the repository at this point in the history
… be used in GF calculation.
  • Loading branch information
CarlosMejZ committed Sep 22, 2023
1 parent 3d3277d commit 41cc116
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
42 changes: 42 additions & 0 deletions tests/ini_input.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

#include "ini_input.hpp"
#include <sstream>

// Misc string functions

Expand Down Expand Up @@ -329,6 +330,25 @@ int INIFile::getData(std::string query) {

} // INIFile::getData<int>

/**
* \brief Specialization of getData to return vector<int> of query
* data field
*
* \param [in] query Formatted query string to be parsed
* \return Value of query data field as a vector<int>
*/
template <>
std::vector<int> INIFile::getData(std::string query) {
std::string line = getData<std::string>(query);
std::istringstream iss( line );
std::vector<int> res;
int tmp;
while( iss >> tmp )
res.push_back(tmp);
return res;

} // INIFile::getData<std::vector<int>>

/**
* \brief Specialization of getData to return bool of query
* data field
Expand All @@ -344,6 +364,28 @@ bool INIFile::getData(std::string query) {

} // INIFile::getData<bool>

/**
* \brief Specialization of getData to return std::vector<bool> of query
* data field
*
* \param [in] query Formatted query string to be parsed
* \return Value of query data field as a std::vector<bool>
*/
template <>
std::vector<bool> INIFile::getData(std::string query) {
std::string line = getData<std::string>(query);
std::istringstream iss( line );
std::vector<bool> res;
std::string tmp;
while( iss >> tmp )
{
bool b = (not tmp.compare("TRUE") or not tmp.compare("ON"));
res.push_back(b);
}
return res;

} // INIFile::getData<std::vector<bool>>

/**
* \brief Specialization of getData to return size_t of query
* data field
Expand Down
10 changes: 4 additions & 6 deletions tests/standalone_driver.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,10 @@ int main(int argc, char** argv) {
OPT_KEYWORD("GF.WRITE", gf_settings.writeGF, bool);
OPT_KEYWORD("GF.PRINT", gf_settings.print, bool);
OPT_KEYWORD("GF.SAVEGFMATS", gf_settings.saveGFmats, bool);
gf_settings.GF_orbs_basis = std::vector<int>(n_active, 0);
for(int i = 0; i < n_active; i++) gf_settings.GF_orbs_basis[i] = i;
gf_settings.GF_orbs_comp = std::vector<int>(n_active, 0);
for(int i = 0; i < n_active; i++) gf_settings.GF_orbs_comp[i] = i;
gf_settings.is_up_basis = std::vector<bool>(n_active, true);
gf_settings.is_up_comp = std::vector<bool>(n_active, true);
OPT_KEYWORD("GF.ORBS_BASIS", gf_settings.GF_orbs_basis, std::vector<int>);
OPT_KEYWORD("GF.IS_UP_BASIS", gf_settings.is_up_basis, std::vector<bool>);
OPT_KEYWORD("GF.ORBS_COMP", gf_settings.GF_orbs_comp, std::vector<int>);
OPT_KEYWORD("GF.IS_UP_COMP", gf_settings.is_up_comp, std::vector<bool>);

// GF vector
std::vector<std::vector<std::complex<double>>> GF(
Expand Down

0 comments on commit 41cc116

Please sign in to comment.