//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& // reblock.cc 2005-10-05 // // In-situ binary reblocking algorithm for error estimation (Flyvbjerg) // demonstrated for mock Markov chain Monte Carlo simulation. // USAGE: // m reblock; reblock (m=make??) // x energy.out // x -settype xydy error.out (x=xmgrace) //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& // Really, I should be using templates here and the vector class in the C++ std library. ... #include // for cout #include // for setf #include // for ofstream using namespace std; ofstream ofs_error("error.out"); const double pi=3.141592653589793238462643383279502884197169399375105820974944; class brb { public: int Lmax,N,imax; double *a,*b; brb (int Lmax, int imax) { // Lmax=entries in buffer, imax=size of each entry this->imax = imax; this->Lmax = Lmax; this->N = 0; a = new double[imax*(Lmax+1)]; // even C++ doesn't do dynamic a[i][j] b = new double[imax*(Lmax+1)]; int i; for (i=0; i>= 1; l++; } } N++; } void report (double *xxmean, double *xxerr) { // PLEASE ENSURE THAT xxmean AND xxerr ARE PROPERLY ALLOCATED BEFORE CALL! int i,l,S,M,Lmax_actual,key; // N is this->N double fractchg; double *SoB; double *aEoMoBM,*aEoEoMoBM; SoB = new double[imax]; aEoMoBM = new double[imax*(Lmax+1)]; aEoEoMoBM = new double[imax*(Lmax+1)]; if (N<=1) { for (i=0; i=0; l--) { cout << l << endl; if ( ((N & (1< 1); t=sqrt(-2*log(u)/u); return t*x; //also t*y } //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& // Main program: Example of using the brb class //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& int main() { int Lmax,Nmax,imax,l,n; double theta,costheta,sintheta,corrlen; double *xx,*xxmean,*xxerr; ofstream ofs_energy("energy.out"); srandom(time(NULL)); // seed random number generator Lmax = 16; // big and safe Nmax = (1<