8#ifndef phoenixSpectrum_hpp
9#define phoenixSpectrum_hpp
28template <
typename _units>
32 typedef typename units::realT realT;
34 static const bool freq =
false;
41 static_cast<realT
>( 1e7 ) / (
static_cast<realT
>( 1e4 ) *
static_cast<realT
>( 1e10 ) );
43 static constexpr const char *dataDirEnvVar =
"PHOENIX_DATADIR";
47 static std::string fileName(
const std::string &name )
54 std::vector<realT> &rawSpectrum,
55 const std::string &path,
70 static void scaleSpectrum( std::vector<realT> &spectrum, realT radius, realT distance )
72 for(
int i = 0; i < spectrum.size(); ++i )
103template <
typename floatT>
105 const std::string &filename,
114 float lambda, flambda;
118 fin.open( filename );
122 std::cerr <<
"Error opening file: " << filename <<
"\n";
126 std::vector<floatT> lambdas;
127 std::vector<floatT> flambdas;
133 fin.getline( line, lineSize );
136 if( sline.length() < 25 )
138 std::cerr <<
"Error reading file: " << filename <<
"\n";
145 if( sline[13] ==
'-' )
151 size_t dpos = sline.find(
'D', nst );
156 if( lambda >= lmin * 1e4 && lambda <= lmax * 1e4 )
158 lambdas.push_back( lambda );
159 flambdas.push_back( flambda );
162 fin.getline( line, lineSize );
167 if( sline.length() < 25 )
170 dpos = sline.find(
'D', nst );
176 if( lambda >= lmin * 1e4 && lambda <= lmax * 1e4 )
178 lambdas.push_back( lambda );
179 flambdas.push_back( flambda );
182 fin.getline( line, lineSize );
192 std::string fname = filename;
193 fout.open( filename );
194 fout.precision( 10 );
196 for(
int i = 0; i < lambdas.size(); ++i )
198 if( sepWavelength == 0 )
200 fout << lambdas[idx[i]] <<
" ";
202 fout << pow( 10, flambdas[idx[i]] + DF ) <<
"\n";
206 if( sepWavelength == 1 )
211 fout.precision( 10 );
212 for(
int i = 0; i < lambdas.size(); ++i )
214 fout << lambdas[idx[i]] <<
"\n";
224template <
typename floatT>
227 std::vector<std::string> flist;
230 int sepWavelength = 1;
231 for(
int i = 0; i < flist.size(); ++i )
Declarations of utilities for working with files.
error_t 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.
void rewritePhoenixSpectrumBatch(const std::string &dir, floatT lmin, floatT lmax, floatT DF=-8.0)
Call rewritePhoenixSpectrum for all files in a directory.
constexpr units::realT parsec()
The parsec.
constexpr units::realT radJupiter()
Radius of Jupiter (nominal equatorial).
error_t
The mxlib error codes.
@ noerror
No error has occurred.
error_t getFileNames(std::vector< std::string > &fileNames, 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.
typeT convertFromString(const std::string &str, error_t *errc=nullptr)
Convert a string to a numerical value.
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 utility to read in columns from a text file.
Utilities for working with strings.
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 constexpr realT wavelengthUnits
Convert from A to SI m.
std::string paramsT
The parameter is a string name.
static error_t readSpectrum(std::vector< realT > &rawLambda, std::vector< realT > &rawSpectrum, const std::string &path, const paramsT ¶ms)
Header for the std::vector utilities.