/*****************************************************
**
**  S-PRES Copyright (c) 2010
**
**  Joshua T Berryman
**
**  This file is part of S-PRES
**
**  S-PRES 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.
**
**  S-PRES 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 this program.  If not, see <http://www.gnu.org/licenses/>.
**
**  If you make use of this program for research 
**  resulting in a publication, please cite:
**
**  Joshua T Berryman and Tanja Schilling, 
**  Sampling rare events in nonequilibrium and nonstationary systems. 
**  
**  J Chem Phys, 133(24):244101, Dec 2010.
**
******************************************************/
#include <iostream>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cstring>

#include "../../spres/src/spres.h"

//** This file contains functions to collect correctly weighted observables over the system states.


void spres::initStateData(){

    dataVector = pt_state->get_derivedData( &dvCount );
    if( dvCount > 0) {
        memset( dataVector, 0, dvCount * sizeof(double) );
    }
}
// **********************************************************************
void spres::collectStateData( double vecWeight ){

    double  *dV;
    int      c;

    dV = pt_state->get_derivedData( &c );  // +++++++++++++++++++++++++++

    if( c != dvCount ){
      cerr << "Error; derived data from state is wrong size: " 
           << c << " != "  << dvCount << endl;
    }

    for( int i  = 0; i < dvCount; i++ ){
        dataVector[i] += ( vecWeight * dV[i] );
    }

    delete[] dV;
}

// **********************************************
void spres::writeDataFile()
{
  for( int i  = 0; i < dvCount; i++ ){
      if( dataVector[i] != 0.0 ) {
          dataLog << i << " " << dataVector[i] << endl;
      }
  }
  dataLog << "\n";
}








