/*
    Copyright (C) 2011 Brendon J. Brewer
    This file is part of DNest, the Diffusive Nested Sampler.

    DNest is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    DNest is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with DNest.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "DNestOptions.h"
#include <fstream>
#include <iostream>

using namespace std;

namespace DNest
{

	DNestOptions::DNestOptions(const char* filename)
	{
		load(filename);
	}

	DNestOptions::DNestOptions(unsigned int numParticles, unsigned int newLevelInterval, unsigned int regularisation, unsigned int saveInterval, unsigned int maxNumLevels, double backTrackLength, double enforceUniformityStrength, unsigned int maxNumSamples)
	:numParticles(numParticles)
	,newLevelInterval(newLevelInterval)
	,regularisation(regularisation)
	,saveInterval(saveInterval)
	,maxNumLevels(maxNumLevels)
	,backTrackLength(backTrackLength)
	,enforceUniformityStrength(enforceUniformityStrength)
	,maxNumSamples(maxNumSamples)
	{

	}

	void DNestOptions::load(const char* filename)
	{
		fstream fin(filename, ios::in);
		if(!fin)
			cerr<<"ERROR: Cannot open file "<<filename<<"."<<endl;

		// Read past comment lines at the top of the file
		while(fin.peek() == '#' || fin.peek() == '%')
			fin.ignore(1000, '\n');

		fin>>numParticles;	fin.ignore(1000, '\n');
		fin>>newLevelInterval;	fin.ignore(1000, '\n');
		fin>>regularisation;	fin.ignore(1000, '\n');
		fin>>saveInterval;	fin.ignore(1000, '\n');
		fin>>maxNumLevels;	fin.ignore(1000, '\n');
		fin>>backTrackLength;		fin.ignore(1000, '\n');
		fin>>enforceUniformityStrength;	fin.ignore(1000, '\n');
		fin>>deleteParticles;		fin.ignore(1000, '\n');
		fin>>maxNumSamples;

		fin.close();
	}
}

