Commit dae581f9 authored by Plaszczynski Stephane's avatar Plaszczynski Stephane
Browse files

Hillipop relative paths

parent d6d46b04
......@@ -6,3 +6,5 @@ list
bt
gdb ../par/example/plikTT_bflike_LCDMPico.par
run ../par/example/plikTT_bflike_LCDMPico.par
run ../par/cobesix/hlpTT_bflike_LCDM.par
where
#COBESIX specific
PYTHONPATH=${PICO_CODE}:$PYTHONPATH
echo "Using project $CMTPATH"
export PYTHONPATH=${PICO_CODE}:$PYTHONPATH
#common
export CLIKDIR
......@@ -33,5 +32,7 @@ if [ ! -h ../par/hillipop_data ] ; then
ln -sf ${HILLIPOP_DATA} ${CAMELROOT}/par/hillipop_data
echo "creating par/hillipop_data link ->${HILLIPOP_DATA}"
fi
echo "Using project $CMTPATH"
#too see details during compilation uncomment
#export VERBOSE=1
#include "HiLLiPOP_3d.hh"
#include "paramfile.h"
#include "fitshandle.h"
#include "cxxutils.h"
#include "cxxsupport/paramfile.h"
#include "cxxsupport/fitshandle.h"
#include "cxxsupport/cxxutils.h"
#include "Parser.hh"
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include<sstream>
#include <libgen.h> //for basename
using namespace std;
......@@ -36,16 +38,19 @@ void HiLLiPOP_3d::Init(const string fileName)
cout << "Using: " << fileName << endl;
paramfile parameters(fileName);
string multipolesFile = parameters.find<string>("MultipolesRange");
string multipolesFile = Parser::getParFile(parameters.find<string>("MultipolesRange"));
string SZFile = Parser::getParFile(parameters.find<string>("SZ"));
string kSZFile = Parser::getParFile(parameters.find<string>("kSZ"));
string pathToBeams = parameters.find<string>("Beams");
string pathToXSpectra = parameters.find<string>("XSpectra");
string pathToXSpectraErrors = parameters.find<string>("XSpectraErrors");
string pathToCovMatrix = parameters.find<string>("CovMatrix");
string SZFile = parameters.find<string>("SZ");
string kSZFile = parameters.find<string>("kSZ");
string pathToCIBSpectra = parameters.find<string>("CIB");
string pathToSZxCIBSpectra = parameters.find<string>("SZxCIB");
string pathToDustSpectra = parameters.find<string>("Dust");
_modeStatus[0] = parameters.find<unsigned int>("TT");
_modeStatus[1] = parameters.find<unsigned int>("EE");
_modeStatus[2] = parameters.find<unsigned int>("BB");
......@@ -194,15 +199,16 @@ void HiLLiPOP_3d::ProcessMultipoles(const string multipolesFile)
void HiLLiPOP_3d::ProcessBeamsEigenmodes(const string pathToBeams)
{
_beamEigenmodes.resize(_nXSpectra);
char beamFile[1024];
for(unsigned int c = 0; c < _nXSpectra; c++) {
sprintf(beamFile,"%s_%dx%d.fits",pathToBeams.c_str(),_XSpectra2Maps[c][0],_XSpectra2Maps[c][1]);
planck_assert(file_present(beamFile),string("missing file : ")+beamFile);
ostringstream os ;
os << pathToBeams << "_" << _XSpectra2Maps[c][0] << "x" << _XSpectra2Maps[c][1] << ".fits";
string beamFile=Parser::getParFile(os.str());
_beamEigenmodes[c].resize(_maxOflmax[0]+1,0);
fitshandle * input = new fitshandle();
input->open(beamFile);
input->goto_hdu(2);
unsigned int size = input->nelems(2);
......@@ -223,18 +229,26 @@ void HiLLiPOP_3d::ProcessXSpectra(const string pathToXSpectra)
{
_ClData.resize(_nXSpectra);
char XSpectrumFile[1024];
//char XSpectrumFile[1024];
for(unsigned int c = 0; c < _nXSpectra; c++) {
// TT - EE - BB - TE
sprintf(XSpectrumFile,"%s_%d_%d.fits",pathToXSpectra.c_str(),_XSpectra2Maps[c][0],_XSpectra2Maps[c][1]);
planck_assert(file_present(XSpectrumFile),string("missing file : ")+XSpectrumFile);
//sprintf(XSpectrumFile,"%s_%d_%d.fits",pathToXSpectra.c_str(),_XSpectra2Maps[c][0],_XSpectra2Maps[c][1]);
//planck_assert(file_present(XSpectrumFile),string("missing file : ")+XSpectrumFile);
ostringstream os ;
os << pathToXSpectra << "_" << _XSpectra2Maps[c][0] << "_" << _XSpectra2Maps[c][1] << ".fits";
string XSpectrumFile=Parser::getParFile(os.str());
fitshandle * input_c1c2 = new fitshandle();
input_c1c2->open(XSpectrumFile);
// ET
sprintf(XSpectrumFile,"%s_%d_%d.fits",pathToXSpectra.c_str(),_XSpectra2Maps[c][1],_XSpectra2Maps[c][0]);
planck_assert(file_present(XSpectrumFile),string("missing file : ")+XSpectrumFile);
os.clear(); os.str("");
os << pathToXSpectra << "_" << _XSpectra2Maps[c][1] << "_" << _XSpectra2Maps[c][0] << ".fits";
XSpectrumFile=Parser::getParFile(os.str());
//sprintf(XSpectrumFile,"%s_%d_%d.fits",pathToXSpectra.c_str(),_XSpectra2Maps[c][1],_XSpectra2Maps[c][0]);
//planck_assert(file_present(XSpectrumFile),string("missing file : ")+XSpectrumFile);
fitshandle * input_c2c1 = new fitshandle();
input_c2c1->open(XSpectrumFile);
......@@ -279,18 +293,28 @@ void HiLLiPOP_3d::ProcessXSpectraErrors(const string pathToXSpectraErrors)
{
_ClWeightData.resize(_nXSpectra);
char XSpectrumFile[1024];
//char XSpectrumFile[1024];
for(unsigned int c = 0; c < _nXSpectra; c++) {
// TT - EE - BB - TE
sprintf(XSpectrumFile,"%s_%d_%d.fits",pathToXSpectraErrors.c_str(),_XSpectra2Maps[c][0],_XSpectra2Maps[c][1]);
planck_assert(file_present(XSpectrumFile),string("missing file : ")+XSpectrumFile);
//sprintf(XSpectrumFile,"%s_%d_%d.fits",pathToXSpectraErrors.c_str(),_XSpectra2Maps[c][0],_XSpectra2Maps[c][1]);
//planck_assert(file_present(XSpectrumFile),string("missing file : ")+XSpectrumFile);
ostringstream os ;
os << pathToXSpectraErrors << "_" << _XSpectra2Maps[c][0] << "_" << _XSpectra2Maps[c][1] << ".fits";
string XSpectrumFile=Parser::getParFile(os.str());
fitshandle * input_c1c2 = new fitshandle();
input_c1c2->open(XSpectrumFile);
// ET
sprintf(XSpectrumFile,"%s_%d_%d.fits",pathToXSpectraErrors.c_str(),_XSpectra2Maps[c][1],_XSpectra2Maps[c][0]);
planck_assert(file_present(XSpectrumFile),string("missing file : ")+XSpectrumFile);
//sprintf(XSpectrumFile,"%s_%d_%d.fits",pathToXSpectraErrors.c_str(),_XSpectra2Maps[c][1],_XSpectra2Maps[c][0]);
//planck_assert(file_present(XSpectrumFile),string("missing file : ")+XSpectrumFile);
os.clear();os.str("");
os << pathToXSpectraErrors << "_" << _XSpectra2Maps[c][1] << "_" << _XSpectra2Maps[c][0] << ".fits";
XSpectrumFile=Parser::getParFile(os.str());
fitshandle * input_c2c1 = new fitshandle();
input_c2c1->open(XSpectrumFile);
......@@ -339,7 +363,7 @@ void HiLLiPOP_3d::ProcessCovMatrix(const string pathToCovMatrix)
string covMatrixFile = pathToCovMatrix+'_';
for(unsigned int m = 0; m < 5; m++) if( _modeStatus[m] == 1 ) covMatrixFile = covMatrixFile+gModeName[m];
covMatrixFile = covMatrixFile+".fits";
covMatrixFile = Parser::getParFile(covMatrixFile+".fits");
cout << "Reading " << covMatrixFile << endl;
planck_assert(file_present(covMatrixFile),string("missing file : ")+covMatrixFile);
......@@ -414,7 +438,10 @@ void HiLLiPOP_3d::ProcessNuisanceParameters(const string SZFile,const string pat
string gFreqPlanckHFI[] = {"100","143","217","353","545","857"};
char tmpPar[32];
char tmpFile[256];
//char tmpFile[256];
string tmpFile;
vector<string>::const_iterator it;
vector<string> freqPlanckHFI(&gFreqPlanckHFI[0],&gFreqPlanckHFI[0]+5);
......@@ -495,9 +522,12 @@ void HiLLiPOP_3d::ProcessNuisanceParameters(const string SZFile,const string pat
// CIB spectra
_ClCIB.resize(_nXFreq);
for(unsigned int f = 0; f < _nXFreq; f++) {
sprintf(tmpFile,"%s_%s.fits",pathToCIBSpectra.c_str(),_XFreq[f].c_str());
//sprintf(tmpFile,"%s_%s.fits",pathToCIBSpectra.c_str(),_XFreq[f].c_str());
//planck_assert(file_present(tmpFile),string("missing file : ")+tmpFile);
planck_assert(file_present(tmpFile),string("missing file : ")+tmpFile);
ostringstream os ;
os << pathToCIBSpectra << "_" << _XFreq[f] << ".fits";
tmpFile=Parser::getParFile(os.str());
fitshandle * CIBInput = new fitshandle();
CIBInput->open(tmpFile);
......@@ -546,8 +576,13 @@ void HiLLiPOP_3d::ProcessNuisanceParameters(const string SZFile,const string pat
// Dust spectra
_ClDust.resize(_nXFreq);
for(unsigned int f = 0; f < _nXFreq; f++) {
sprintf(tmpFile,"%s_%s.fits",pathToDustSpectra.c_str(),_XFreq[f].c_str());
planck_assert(file_present(tmpFile),string("missing file : ")+tmpFile);
//sprintf(tmpFile,"%s_%s.fits",pathToDustSpectra.c_str(),_XFreq[f].c_str());
//planck_assert(file_present(tmpFile),string("missing file : ")+tmpFile);
ostringstream os ;
os << pathToDustSpectra << "_" << _XFreq[f] << ".fits";
tmpFile=Parser::getParFile(os.str());
_ClDust[f].resize(5*(_maxOflmax[0]+1),0);
......@@ -607,9 +642,13 @@ void HiLLiPOP_3d::ProcessNuisanceParameters(const string SZFile,const string pat
// Begin: tSZxCIB spectra
_ClSZxCIB.resize(_nXFreq);
for(unsigned int f = 0; f < _nXFreq; f++) {
sprintf(tmpFile,"%s_%s.fits",pathToSZxCIBSpectra.c_str(),_XFreq[f].c_str());
//sprintf(tmpFile,"%s_%s.fits",pathToSZxCIBSpectra.c_str(),_XFreq[f].c_str());
//planck_assert(file_present(tmpFile),string("missing file : ")+tmpFile);
ostringstream os ;
os << pathToSZxCIBSpectra << "_" << _XFreq[f] << ".fits";
tmpFile=Parser::getParFile(os.str());
planck_assert(file_present(tmpFile),string("missing file : ")+tmpFile);
fitshandle * SZxCIBInput = new fitshandle();
SZxCIBInput->open(tmpFile);
......
......@@ -10,6 +10,7 @@
//
// History (add to end):
// creation: Tue Oct 8 14:40:00 CET 2013
// test for DirNames in case it is relative : 31/08/2015
//
//------------------------------------------------------------------------
......
......@@ -31,6 +31,7 @@
//--------------------
// C
//----------------
#include <sys/stat.h>
using namespace std;
//---------------
......@@ -176,9 +177,24 @@ Parser::getParFile(const std::string& filename){
string s=filename;
if (!file_present(filename)) {
s=string(PARFILE)+"/"+filename;
// cout << "! No direct access file: " << filename << ". Looking into: " << s << "..." "\t";
cout << "* Checking for relative access path =>" << s << "...";
assert_present(s);
//cout << "...OK found" << endl;
cout << "...OK found" << endl;
}
return s;
}
std::string
Parser::getParDir(const std::string& dirname){
string s=dirname;
struct stat sb;
if (! (stat(s.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode))) {
s=string(PARFILE)+"/"+dirname;
if (! (stat(s.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode))) {
planck_assert(false, s+" dir does not exist");
}
}
return s;
}
......@@ -47,8 +47,9 @@ public:
inline bool mnContours() {return params.find<bool>("computecontour",false);}
//inline string precisionFile() {return params.find<string>("precisionFile","");}
//utlity to read filenames: if not found look into PARFILE dir (defined through macro)
//utlity to read filenames/dir: if not found look into PARFILE dir (defined through macro)
static std::string getParFile(const std::string& filename);
static std::string getParDir(const std::string& dirname);
//parameters
std::vector<string> parNames;
......
......@@ -290,3 +290,16 @@ void parse_file (const string &filename, map<string,string> &dict)
}
}
}
string DirName(string source)
{
if (source.size() <= 1) //Make sure it's possible to check the last character.
{
return source;
}
if (*(source.rbegin() + 1) == '/') //Remove trailing slash if it exists.
{
source.erase(source.size()-1,1);
}
source.erase(std::find(source.rbegin(), source.rend(), '/').base(), source.end());
return source;
}
......@@ -262,4 +262,9 @@ inline unsigned int healpix_repcount (int npix)
return isqrt (npix/12);
}
//acess directory name without trailing slash
std::string DirName (std::string x);
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment