8 #ifndef phoenixSpectrum_hpp
9 #define phoenixSpectrum_hpp
12 #include "../math/vectorUtils.hpp"
13 #include "../ioutils/fileUtils.hpp"
23 template<
typename _units>
27 typedef typename units::realT realT;
29 static const bool freq =
false;
35 static constexpr realT
fluxUnits =
static_cast<realT
>(1e7) / (
static_cast<realT
>(1e4)*
static_cast<realT
>(1e10));
37 static constexpr
const char * dataDirEnvVar =
"PHOENIX_DATADIR";
41 static std::string fileName(
const std::string & name )
47 std::vector<realT> & rawSpectrum,
48 const std::string & path ,
59 static void scaleSpectrum( std::vector<realT> & spectrum,
64 for(
int i=0; i < spectrum.size(); ++i)
66 spectrum[i] *= pow( radius / distance * ( constants::radJupiter<units>() / constants::parsec<units>()), 2);
95 template<
typename floatT>
99 int sepWavelength = 0,
103 float lambda, flambda;
111 std::cerr <<
"Error opening file: " << filename <<
"\n";
115 std::vector<floatT> lambdas;
116 std::vector<floatT> flambdas;
122 fin.getline(line, lineSize);
125 if(sline.length() < 25)
127 std::cerr <<
"Error reading file: " << filename <<
"\n";
130 lambda = ioutils::convertFromString<floatT>(sline.substr(1,12));
134 if(sline[13] ==
'-') nst = 13;
138 size_t dpos = sline.find(
'D', nst);
142 flambda = ioutils::convertFromString<floatT>(sline.substr(nst,12));
144 if(lambda >= lmin*1e4 && lambda <= lmax*1e4)
146 lambdas.push_back(lambda);
147 flambdas.push_back(flambda);
150 fin.getline(line, lineSize);
155 if(sline.length() < 25)
continue;
157 dpos = sline.find(
'D', nst);
160 lambda = ioutils::convertFromString<floatT>(sline.substr(1,12));
161 flambda = ioutils::convertFromString<floatT>(sline.substr(nst,12));
163 if(lambda >= lmin*1e4 && lambda <= lmax*1e4)
165 lambdas.push_back(lambda);
166 flambdas.push_back(flambda);
169 fin.getline(line, lineSize);
179 std::string fname = filename;
183 for(
int i=0;i<lambdas.size(); ++i)
185 if(sepWavelength == 0)
187 fout << lambdas[idx[i]] <<
" ";
189 fout << pow(10, flambdas[idx[i]] + DF) <<
"\n";
193 if(sepWavelength == 1)
199 for(
int i=0;i<lambdas.size(); ++i)
201 fout << lambdas[idx[i]] <<
"\n";
211 template<
typename floatT>
212 void rewritePhoenixSpectrumBatch(
const std::string & dir,
220 int sepWavelength = 1;
221 for(
int i=0; i< flist.size(); ++i)
224 if(i == 0) sepWavelength = -1;
int readColumns(const std::string &fname, arrTs &... arrays)
Read in columns from a text file.
void rewritePhoenixSpectrum(const std::string &filename, floatT lmin, floatT lmax, int sepWavelength=0, floatT DF=-8.0)
Read in, crop, scale, and re-write a Phoenix spectrum data file.
std::vector< std::string > getFileNames(const std::string &directory, const std::string &prefix, const std::string &substr, const std::string &extension)
Get a list of file names from the specified directory, specifying a prefix, a substring to match,...
std::string parentPath(const std::string &fname)
Get the parent path from a filename.
std::vector< size_t > vectorSortOrder(std::vector< memberT > const &values)
Return the indices of the vector in sorted order, without altering the vector itself.
A spectrum from the Phoenix model, for use with ioutils::astro::astroSpectrum.
static constexpr realT fluxUnits
Convert from erg s-1 cm-2 A-1 to SI W m-3.
static int readSpectrum(std::vector< realT > &rawLambda, std::vector< realT > &rawSpectrum, const std::string &path, const paramsT ¶ms)
static constexpr realT wavelengthUnits
Convert from A to SI m.
std::string paramsT
The parameter is a string name.