da3d4e0e
dmayerich
Initial commit.
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
#include "globals.h"
#include <sstream>
#include <fstream>
#include <iostream>
using namespace std;
vector<SpecPair> LoadSpectrum(string filename)
{
//load a spectrum from a file and resample to 2wn intervals
//create the spectrum
vector<SpecPair> S;
//open the file
ifstream inFile(filename.c_str());
SpecPair temp;
while(!inFile.eof()){
inFile>>temp.nu;
inFile>>temp.A;
S.push_back(temp);
}
//compute the minimum and maximum input wavenumbers
|
52a5fe9d
dmayerich
Added double supp...
|
26
27
|
double inMin = S.front().nu;
double inMax = S.back().nu;
|
da3d4e0e
dmayerich
Initial commit.
|
28
|
|
52a5fe9d
dmayerich
Added double supp...
|
29
30
|
int nuMin = (int)ceil(inMin);
int nuMax = (int)floor(inMax);
|
da3d4e0e
dmayerich
Initial commit.
|
31
32
33
34
35
36
37
38
39
40
41
|
//make sure both are either even or odd
if(nuMin % 2 != nuMax % 2)
nuMax--;
//compute the number of values in the resampled spectrum
int nVals = (nuMax - nuMin)/2 + 1;
//allocate space for the spectrum
vector<SpecPair> outSpec;
|
52a5fe9d
dmayerich
Added double supp...
|
42
|
double nu, highVal, lowVal, a;
|
da3d4e0e
dmayerich
Initial commit.
|
43
44
45
46
47
48
49
50
51
52
53
54
|
int j=1;
for(int i=0; i<nVals; i++)
{
nu = nuMin + i * 2;
temp.nu = nu;
//handle the boundary cases
if(nu < inMin || nu > inMax)
temp.A = 0.0;
else
{
//move to the correct position in the input array
|
52a5fe9d
dmayerich
Added double supp...
|
55
|
while(j < (int)S.size()-1 && S[j].nu <= nu)
|
da3d4e0e
dmayerich
Initial commit.
|
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
j++;
lowVal = S[j-1].nu;
highVal = S[j].nu;
a = (nu - lowVal)/(highVal - lowVal);
temp.A = S[j-1].A * (1.0 - a) + S[j].A * a;
}
outSpec.push_back(temp);
}
return outSpec;
}
vector<SpecPair> SetReferenceSpectrum(char* text)
{
stringstream inString(text);
//create the spectrum
vector<SpecPair> S;
SpecPair temp;
while(!inString.eof()){
inString>>temp.nu;
inString>>temp.A;
S.push_back(temp);
}
return S;
}
void SaveK(string fileName)
{
ofstream outFile(fileName.c_str());
|
52a5fe9d
dmayerich
Added double supp...
|
91
|
for(unsigned int i=0; i<EtaK.size(); i++)
|
da3d4e0e
dmayerich
Initial commit.
|
92
93
94
95
96
97
98
99
100
101
|
{
outFile<<EtaK[i].nu<<" ";
outFile<<EtaK[i].A<<endl;
}
outFile.close();
}
void SaveN(string fileName)
{
ofstream outFile(fileName.c_str());
|
52a5fe9d
dmayerich
Added double supp...
|
102
|
for(unsigned int i=0; i<EtaN.size(); i++)
|
da3d4e0e
dmayerich
Initial commit.
|
103
104
105
106
107
108
109
110
111
112
|
{
outFile<<EtaN[i].nu<<" ";
outFile<<EtaN[i].A<<endl;
}
outFile.close();
}
void SaveSimulation(string fileName)
{
ofstream outFile(fileName.c_str());
|
bfe3f56b
dmayerich
Fixed Linux compa...
|
113
|
outFile.precision(10);
|
52a5fe9d
dmayerich
Added double supp...
|
114
|
for(unsigned int i=0; i<SimSpectrum.size(); i++)
|
da3d4e0e
dmayerich
Initial commit.
|
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
{
outFile<<SimSpectrum[i].nu<<" ";
outFile<<SimSpectrum[i].A<<endl;
}
outFile.close();
}
void SaveState()
{
ofstream outFile("main.prj");
//Window Parameters
outFile<<nuMin<<endl;
outFile<<nuMax<<endl;
outFile<<aMin<<endl;
outFile<<aMax<<endl;
outFile<<dNu<<endl;
//material parameters
outFile<<radius<<endl;
outFile<<baseIR<<endl;
outFile<<cA<<endl;
//optical parameters
outFile<<cNAi<<endl;
outFile<<cNAo<<endl;
outFile<<oNAi<<endl;
outFile<<oNAo<<endl;
outFile.close();
}
void LoadState()
{
ifstream inFile("main.prj");
//Window Parameters
inFile>>nuMin;
inFile>>nuMax;
inFile>>aMin;
inFile>>aMax;
inFile>>dNu;
//material parameters
inFile>>radius;
inFile>>baseIR;
inFile>>cA;
//optical parameters
inFile>>cNAi;
inFile>>cNAo;
inFile>>oNAi;
inFile>>oNAo;
inFile.close();
}
void SetDefaults()
{
nuMin = 800;
nuMax = 4000;
dNu = 2;
aMin = 0;
aMax = 1;
//material parameters
radius = 4.0f;
baseIR = 1.49f;
cA = 1.0;
vector<SpecPair> KMaterial;
vector<SpecPair> NMaterial;
//optical parameters
cNAi = 0.0;
cNAo = 0.6;
oNAi = 0.0;
oNAo = 0.6;
}
|