Skip to content

Commit

Permalink
Merge pull request #2 from LBNL-ETA/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
StephenCzarnecki authored Mar 16, 2022
2 parents d73a371 + a718bad commit 80bb302
Show file tree
Hide file tree
Showing 34 changed files with 611 additions and 636 deletions.
2 changes: 1 addition & 1 deletion .clang_format → .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ BreakBeforeBraces: 'Custom'
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: 'AfterColon'
ColumnLimit: 100
ColumnLimit: 150
#CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
Expand Down
6 changes: 3 additions & 3 deletions include/windows_standards/windows_standard.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
#define WINDOW_STANDARDS_WINDOW_STANDARD_H

#include "../../src/integration_rule.h"
#include "../../src/load_standard.h"
#include "../../src/method.h"
#include "../../src/load_optical_standard.h"
#include "../../src/optical_standard_method.h"
#include "../../src/spectrum.h"
#include "../../src/standard.h"
#include "../../src/optical_standard.h"
#include "../../src/wavelength_boundary.h"
#include "../../src/wavelength_set.h"

Expand Down
11 changes: 5 additions & 6 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ add_library( ${LIB_NAME}
integration_rule.h
create_integration_rule.h
create_integration_rule.cpp
load_standard.h
load_standard.cpp
load_optical_standard.h
load_optical_standard.cpp
create_spectrum.h
create_spectrum.cpp
method.h
method.cpp
method_text.h
optical_standard_method.h
optical_standard_method_text.h
create_wavelength_boundary.h
create_wavelength_boundary.cpp
spectrum.h
standard.h
optical_standard.h
create_wavelength_set.h
create_wavelength_set.cpp
wavelength_boundary.h
Expand Down
56 changes: 29 additions & 27 deletions src/create_integration_rule.cpp
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
#include "create_integration_rule.h"

#include <regex>

Integration_Rule create_integration_rule(std::string const& line)
namespace window_standards
{
Integration_Rule integration_rule;
Integration_Rule create_integration_rule(std::string const & line)
{
Integration_Rule integration_rule;

if(line.find("Trapezoidal") != std::string::npos)
{
integration_rule.type = Integration_Rule_Type::TRAPEZOIDAL;
integration_rule.k = 1;
}
else if(line.find("Rectangular") != std::string::npos)
{
integration_rule.type = Integration_Rule_Type::RECTANGULAR;
integration_rule.k = 1;
}
else if(line.find("Table") != std::string::npos)
{
integration_rule.type = Integration_Rule_Type::TABLE;
integration_rule.k = 1;
}
if(line.find("Trapezoidal") != std::string::npos)
{
integration_rule.type = Integration_Rule_Type::TRAPEZOIDAL;
integration_rule.k = 1;
}
else if(line.find("Rectangular") != std::string::npos)
{
integration_rule.type = Integration_Rule_Type::RECTANGULAR;
integration_rule.k = 1;
}
else if(line.find("Table") != std::string::npos)
{
integration_rule.type = Integration_Rule_Type::TABLE;
integration_rule.k = 1;
}

std::regex pattern(".*k=(\\S+)\\).*");
std::smatch matches;
if(std::regex_search(line, matches, pattern))
{
std::string k = matches[1].str();
integration_rule.k = std::stod(k);
}
return integration_rule;
}
std::regex pattern(".*k=(\\S+)\\).*");
std::smatch matches;
if(std::regex_search(line, matches, pattern))
{
std::string k = matches[1].str();
integration_rule.k = std::stod(k);
}
return integration_rule;
}
} // namespace window_standards
12 changes: 7 additions & 5 deletions src/create_integration_rule.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#ifndef WINDOWS_STANDARDS_CREATE_INTEGRATION_RULE_H_
#define WINDOWS_STANDARDS_CREATE_INTEGRATION_RULE_H_
#ifndef WINDOW_STANDARDS_CREATE_INTEGRATION_RULE_H_
#define WINDOW_STANDARDS_CREATE_INTEGRATION_RULE_H_

#include <string>
#include "integration_rule.h"
#include <string>

Integration_Rule create_integration_rule(std::string const& line);

namespace window_standards
{
Integration_Rule create_integration_rule(std::string const &line);
}
#endif
177 changes: 88 additions & 89 deletions src/create_spectrum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,112 +3,111 @@

#include "create_spectrum.h"
#include "util.h"

Spectrum load_spectrum(std::istream & input)
namespace window_standards
{
Spectrum spectrum;
std::string line;
double multiplier = 1.0;
Spectrum load_spectrum(std::istream & input)
{
Spectrum spectrum;
std::string line;
double multiplier = 1.0;

spectrum.type = Spectrum_Type::FILE;
spectrum.type = Spectrum_Type::FILE;

while(std::getline(input, line))
{
std::string line_lower = to_lower(line);
if(line_lower.find("description") != std::string::npos)
while(std::getline(input, line))
{
std::string description = line.substr(line.find(":") + 2);
spectrum.description = description;
continue;
}
if(line_lower.find("type") != std::string::npos)
{
continue;
}
if(line_lower.find("wavelength units") != std::string::npos)
{
if((line_lower.find("nanometer") != std::string::npos)
|| (line_lower.find("nm") != std::string::npos))
std::string line_lower = to_lower(line);
if(line_lower.find("description") != std::string::npos)
{
multiplier *= .001;
std::string description = line.substr(line.find(":") + 2);
spectrum.description = description;
continue;
}
if(line_lower.find("type") != std::string::npos)
{
continue;
}
if(line_lower.find("wavelength units") != std::string::npos)
{
if((line_lower.find("nanometer") != std::string::npos) || (line_lower.find("nm") != std::string::npos))
{
multiplier *= .001;
}
continue;
}
continue;
}

std::regex pattern("\\s*(\\S+)\\s+(\\S+)\\s*");
std::smatch matches;
std::regex pattern("\\s*(\\S+)\\s+(\\S+)\\s*");
std::smatch matches;

if(std::regex_search(line, matches, pattern))
{
std::string wl = matches[1].str();
std::string val = matches[2].str();
spectrum.values.push_back(
std::make_pair<double, double>(std::stod(wl) * multiplier, std::stod(val)));
if(std::regex_search(line, matches, pattern))
{
std::string wl = matches[1].str();
std::string val = matches[2].str();
spectrum.values.push_back(std::make_pair<double, double>(std::stod(wl) * multiplier, std::stod(val)));
}
}
}

return spectrum;
}

Spectrum load_spectrum(std::string const & path)
{
std::ifstream fin(path);
return load_spectrum(fin);
}

Spectrum create_spectrum(std::string const & line, std::string const & standard_directory)
{
Spectrum spectrum;
return spectrum;
}

if(line.find("None") != std::string::npos)
Spectrum load_spectrum(std::string const & path)
{
spectrum.type = Spectrum_Type::NONE;
spectrum.description = "None";
std::ifstream fin(path);
return load_spectrum(fin);
}
else if(line.find("Blackbody") != std::string::npos && line.find(".SSP") == std::string::npos)

Spectrum create_spectrum(std::string const & line, std::string const & standard_directory)
{
spectrum.type = Spectrum_Type::BLACKBODY;
spectrum.description = "Blackbody";
Spectrum spectrum;

std::regex pattern(".*T=(.*)K\\)");
// auto itr = std::sregex_iterator(line.begin(), line.end(), pattern);
// std::string val = itr->str();
std::smatch matches;
if(std::regex_search(line, matches, pattern))
if(line.find("None") != std::string::npos)
{
std::string val = matches[1].str();
spectrum.t = std::stod(val);
spectrum.type = Spectrum_Type::NONE;
spectrum.description = "None";
}
}
else if(line.find("UV Action") != std::string::npos && line.find(".SSP") == std::string::npos)
{
spectrum.type = Spectrum_Type::UV_ACTION;
spectrum.description = "UV Action";
std::regex pattern(".*a=(.*), b=(.*)\\)");
// auto itr = std::sregex_iterator(line.begin(), line.end(), pattern);
// std::string a = itr->str(1);
// std::string a = itr->str(2);
std::smatch matches;
if(std::regex_search(line, matches, pattern))
else if(line.find("Blackbody") != std::string::npos && line.find(".SSP") == std::string::npos)
{
std::string a = matches[1].str();
std::string b = matches[2].str();
spectrum.a = std::stod(a);
spectrum.b = std::stod(b);
spectrum.type = Spectrum_Type::BLACKBODY;
spectrum.description = "Blackbody";

std::regex pattern(".*T=(.*)K\\)");
// auto itr = std::sregex_iterator(line.begin(), line.end(), pattern);
// std::string val = itr->str();
std::smatch matches;
if(std::regex_search(line, matches, pattern))
{
std::string val = matches[1].str();
spectrum.t = std::stod(val);
}
}
else if(line.find("UV Action") != std::string::npos && line.find(".SSP") == std::string::npos)
{
spectrum.type = Spectrum_Type::UV_ACTION;
spectrum.description = "UV Action";
std::regex pattern(".*a=(.*), b=(.*)\\)");
// auto itr = std::sregex_iterator(line.begin(), line.end(), pattern);
// std::string a = itr->str(1);
// std::string a = itr->str(2);
std::smatch matches;
if(std::regex_search(line, matches, pattern))
{
std::string a = matches[1].str();
std::string b = matches[2].str();
spectrum.a = std::stod(a);
spectrum.b = std::stod(b);
}
}
else if((line.find("Krochmann") != std::string::npos) && (line.find(".SSP") == std::string::npos))
{
spectrum.type = Spectrum_Type::KROCHMANN;
spectrum.description = "Krochmann";
}
else
{
std::string spectum_path = standard_directory;
spectum_path += line;
spectrum = load_spectrum(spectum_path);
}
}
else if((line.find("Krochmann") != std::string::npos)
&& (line.find(".SSP") == std::string::npos))
{
spectrum.type = Spectrum_Type::KROCHMANN;
spectrum.description = "Krochmann";
}
else
{
std::string spectum_path = standard_directory;
spectum_path += line;
spectrum = load_spectrum(spectum_path);
}

return spectrum;
}
return spectrum;
}
} // namespace window_standards
13 changes: 7 additions & 6 deletions src/create_spectrum.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#ifndef WINDOWS_STANDARDS_CREATE_SPECTRUM_H_
#define WINDOWS_STANDARDS_CREATE_SPECTRUM_H_
#ifndef WINDOW_STANDARDS_CREATE_SPECTRUM_H_
#define WINDOW_STANDARDS_CREATE_SPECTRUM_H_

#include <string>

#include "spectrum.h"

Spectrum load_spectrum(std::istream & input);
Spectrum create_spectrum(std::string const& line, std::string const& standard_directory);

namespace window_standards
{
Spectrum load_spectrum(std::istream & input);
Spectrum create_spectrum(std::string const& line, std::string const& standard_directory);
}
#endif
30 changes: 16 additions & 14 deletions src/create_wavelength_boundary.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
#include "create_wavelength_boundary.h"


Wavelength_Boundary create_wavelength_boundary(std::string const& line)
namespace window_standards
{
Wavelength_Boundary wavelength_boundary;
Wavelength_Boundary create_wavelength_boundary(std::string const & line)
{
Wavelength_Boundary wavelength_boundary;

if(line.find("Wavelength set") != std::string::npos)
{
wavelength_boundary.type = Wavelength_Boundary_Type::WAVELENGTH_SET;
}
else
{
wavelength_boundary.type = Wavelength_Boundary_Type::NUMBER;
wavelength_boundary.value = std::stod(line);
}
if(line.find("Wavelength set") != std::string::npos)
{
wavelength_boundary.type = Wavelength_Boundary_Type::WAVELENGTH_SET;
}
else
{
wavelength_boundary.type = Wavelength_Boundary_Type::NUMBER;
wavelength_boundary.value = std::stod(line);
}

return wavelength_boundary;
}
return wavelength_boundary;
}
} // namespace window_standards
Loading

0 comments on commit 80bb302

Please sign in to comment.