Commit 9d0ef8e6 authored by Pierre Aubert's avatar Pierre Aubert
Browse files

Add save function to histogram

parent 53e86d6b
Pipeline #118674 passed with stages
in 38 seconds
......@@ -19,6 +19,7 @@ class PHistogram{
PHistogram(const PHistogram<T> & other);
virtual ~PHistogram();
bool save(const std::string & fileName) const;
void resize(size_t nbValue);
void setRange(T min, T max);
void reset();
......
......@@ -55,6 +55,25 @@ PHistogram<T>::~PHistogram(){
}
}
///Fonction qui permet de sauvegarder la PFunction dans un fichier
/** @param fileName : nom du fichier de sauvegarde
* @return true si la fonction a réussie, false sinon
*/
template<typename T>
bool PHistogram<T>::save(const std::string & fileName) const{
std::ofstream fs;
fs.open(fileName.c_str());
if(!fs.is_open()){return false;}
T dx = p_xRange/((T)p_nbValue);
for(long unsigned int i(0lu); i < p_nbValue; ++i){
fs << (dx*((T)i) + p_xMin) << "\t" << p_value[i] << "\n";
}
fs << (dx*((T)p_nbValue) + p_xMin) << "\t" << 0 << "\n";
fs.close();
return true;
}
///Resize the PHistogram
/** @param nbValue ; number of bins of the PHistogram
*/
......
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