6
6
7
7
Spectrum load_spectrum (std::istream & input)
8
8
{
9
- Spectrum spectrum;
10
- std::string line;
11
- double multiplier = 1.0 ;
9
+ Spectrum spectrum;
10
+ std::string line;
11
+ double multiplier = 1.0 ;
12
12
13
- spectrum.type = Spectrum_Type::FILE;
13
+ spectrum.type = Spectrum_Type::FILE;
14
14
15
- while (std::getline (input, line))
16
- {
17
- std::string line_lower = to_lower (line);
18
- if (line_lower.find (" description" ) != std::string::npos)
19
- {
20
- std::string description = line.substr (line.find (" :" ) + 2 );
21
- spectrum.description = description;
22
- continue ;
23
- }
24
- if (line_lower.find (" type" ) != std::string::npos)
25
- {
26
- continue ;
27
- }
28
- if (line_lower.find (" wavelength units" ) != std::string::npos)
29
- {
30
- // Just check for "anometer" to cover Nanometer, nanometer, Nanometers, nanometers
31
- // Rather than have to deal with tolower and issues it brings in
32
- if (line_lower.find (" nanometer" ) != std::string::npos)
33
- {
34
- multiplier *= .001 ;
35
- }
36
- continue ;
37
- }
15
+ while (std::getline (input, line))
16
+ {
17
+ std::string line_lower = to_lower (line);
18
+ if (line_lower.find (" description" ) != std::string::npos)
19
+ {
20
+ std::string description = line.substr (line.find (" :" ) + 2 );
21
+ spectrum.description = description;
22
+ continue ;
23
+ }
24
+ if (line_lower.find (" type" ) != std::string::npos)
25
+ {
26
+ continue ;
27
+ }
28
+ if (line_lower.find (" wavelength units" ) != std::string::npos)
29
+ {
30
+ if ((line_lower.find (" nanometer" ) != std::string::npos)
31
+ || (line_lower.find (" nm" ) != std::string::npos))
32
+ {
33
+ multiplier *= .001 ;
34
+ }
35
+ continue ;
36
+ }
38
37
39
- std::regex pattern (" \\ s*(\\ S+)\\ s+(\\ S+)\\ s*" );
40
- std::smatch matches;
38
+ std::regex pattern (" \\ s*(\\ S+)\\ s+(\\ S+)\\ s*" );
39
+ std::smatch matches;
41
40
42
- if (std::regex_search (line, matches, pattern))
43
- {
44
- std::string wl = matches[1 ].str ();
45
- std::string val = matches[2 ].str ();
46
- spectrum.values .push_back (std::make_pair<double , double >(std::stod (wl) * multiplier, std::stod (val)));
47
- }
48
- }
41
+ if (std::regex_search (line, matches, pattern))
42
+ {
43
+ std::string wl = matches[1 ].str ();
44
+ std::string val = matches[2 ].str ();
45
+ spectrum.values .push_back (
46
+ std::make_pair<double , double >(std::stod (wl) * multiplier, std::stod (val)));
47
+ }
48
+ }
49
49
50
- return spectrum;
50
+ return spectrum;
51
51
}
52
52
53
- Spectrum load_spectrum (std::string const & path)
53
+ Spectrum load_spectrum (std::string const & path)
54
54
{
55
- std::ifstream fin (path);
56
- return load_spectrum (fin);
55
+ std::ifstream fin (path);
56
+ return load_spectrum (fin);
57
57
}
58
58
59
- Spectrum create_spectrum (std::string const & line, std::string const & standard_directory)
59
+ Spectrum create_spectrum (std::string const & line, std::string const & standard_directory)
60
60
{
61
- Spectrum spectrum;
61
+ Spectrum spectrum;
62
62
63
- if (line.find (" None" ) != std::string::npos)
64
- {
65
- spectrum.type = Spectrum_Type::NONE;
66
- spectrum.description = " None" ;
67
- }
68
- else if (line.find (" Blackbody" ) != std::string::npos
69
- && line.find (" .SSP" ) == std::string::npos)
70
- {
71
- spectrum.type = Spectrum_Type::BLACKBODY;
72
- spectrum.description = " Blackbody" ;
63
+ if (line.find (" None" ) != std::string::npos)
64
+ {
65
+ spectrum.type = Spectrum_Type::NONE;
66
+ spectrum.description = " None" ;
67
+ }
68
+ else if (line.find (" Blackbody" ) != std::string::npos && line.find (" .SSP" ) == std::string::npos)
69
+ {
70
+ spectrum.type = Spectrum_Type::BLACKBODY;
71
+ spectrum.description = " Blackbody" ;
73
72
74
- std::regex pattern (" .*T=(.*)K\\ )" );
75
- // auto itr = std::sregex_iterator(line.begin(), line.end(), pattern);
76
- // std::string val = itr->str();
77
- std::smatch matches;
78
- if (std::regex_search (line, matches, pattern))
79
- {
80
- std::string val = matches[1 ].str ();
81
- spectrum.t = std::stod (val);
82
- }
83
- }
84
- else if (line.find (" UV Action" ) != std::string::npos
85
- && line.find (" .SSP" ) == std::string::npos)
86
- {
87
- spectrum.type = Spectrum_Type::UV_ACTION;
88
- spectrum.description = " UV Action" ;
89
- std::regex pattern (" .*a=(.*), b=(.*)\\ )" );
90
- // auto itr = std::sregex_iterator(line.begin(), line.end(), pattern);
91
- // std::string a = itr->str(1);
92
- // std::string a = itr->str(2);
93
- std::smatch matches;
94
- if (std::regex_search (line, matches, pattern))
95
- {
96
- std::string a = matches[1 ].str ();
97
- std::string b = matches[2 ].str ();
98
- spectrum.a = std::stod (a);
99
- spectrum.b = std::stod (b);
100
- }
73
+ std::regex pattern (" .*T=(.*)K\\ )" );
74
+ // auto itr = std::sregex_iterator(line.begin(), line.end(), pattern);
75
+ // std::string val = itr->str();
76
+ std::smatch matches;
77
+ if (std::regex_search (line, matches, pattern))
78
+ {
79
+ std::string val = matches[1 ].str ();
80
+ spectrum.t = std::stod (val);
81
+ }
82
+ }
83
+ else if (line.find (" UV Action" ) != std::string::npos && line.find (" .SSP" ) == std::string::npos)
84
+ {
85
+ spectrum.type = Spectrum_Type::UV_ACTION;
86
+ spectrum.description = " UV Action" ;
87
+ std::regex pattern (" .*a=(.*), b=(.*)\\ )" );
88
+ // auto itr = std::sregex_iterator(line.begin(), line.end(), pattern);
89
+ // std::string a = itr->str(1);
90
+ // std::string a = itr->str(2);
91
+ std::smatch matches;
92
+ if (std::regex_search (line, matches, pattern))
93
+ {
94
+ std::string a = matches[1 ].str ();
95
+ std::string b = matches[2 ].str ();
96
+ spectrum.a = std::stod (a);
97
+ spectrum.b = std::stod (b);
98
+ }
99
+ }
100
+ else if ((line.find (" Krochmann" ) != std::string::npos)
101
+ && (line.find (" .SSP" ) == std::string::npos))
102
+ {
103
+ spectrum.type = Spectrum_Type::KROCHMANN;
104
+ spectrum.description = " Krochmann" ;
105
+ }
106
+ else
107
+ {
108
+ std::string spectum_path = standard_directory;
109
+ spectum_path += line;
110
+ spectrum = load_spectrum (spectum_path);
111
+ }
101
112
102
- }
103
- else if ((line.find (" Krochmann" ) != std::string::npos)
104
- && (line.find (" .SSP" ) == std::string::npos))
105
- {
106
- spectrum.type = Spectrum_Type::KROCHMANN;
107
- spectrum.description = " Krochmann" ;
108
- }
109
- else
110
- {
111
- std::string spectum_path = standard_directory;
112
- spectum_path += line;
113
- spectrum = load_spectrum (spectum_path);
114
- }
115
-
116
- return spectrum;
117
- }
113
+ return spectrum;
114
+ }
0 commit comments