% avscript
% prepares driving script for calculations of TABS
% from FF and TEN files for the time-averagning approximation
% Grahnen & Kubelka JCPB 2010, Auer & Skinner JCP 2007
% FF and TEN must be calculated by averagin the potential
% (.PSI) files over N2av frames.
% This script reads files named <fname>.<XXXXX>.FF and <fname>.<XXXXX>.TEN
% where fname is specified below and XXXXX are frame numbers
% the driving script is saved as 'av<N2av>'
clear all;
%
fname='p22full';
N2av=59;
%
nmax=10000;
step=1;
ntot=floor((nmax-N2av+1)/step)+1;
nstart=1;
%
fid1=fopen('go59','w');
%
for iav=1:ntot
    ifn=int2str(iav);
    if nstart<1000
       if nstart<10
          ist=strcat('000',int2str(nstart));
       elseif nstart<100
          ist=strcat('00',int2str(nstart));
       else
          ist=strcat('0',int2str(nstart));
       end
    else
          ist=int2str(nstart);
    end
%
    fprintf(fid1,'rm FILE.FC \n');
    fprintf(fid1,'rm FILE.TEN \n');
    fprintf(fid1,'rm FILE2.TEN \n');
    fprintf(fid1,'rm F.INP \n');
    fprintf(fid1,'rm F2.INP \n');
    fprintf(fid1,'cp %s FILE2.TEN \n',strcat('../',fname,'.',ist,'.TEN'));
    fprintf(fid1,'cp %s FILE.FC \n',strcat('../psi',int2str(N2av),'_',ifn,'.FC'));
    fprintf(fid1,'cp %s FILE.TEN \n',strcat('../psi',int2str(N2av),'_',ifn,'.TEN'));
    fprintf(fid1,'$HOME/New/new4 \n');
    fprintf(fid1,'cp F.INP F2.INP \n');
    fprintf(fid1,'$HOME/New/new5a \n');
    fprintf(fid1,'cp DOG.TAB %s \n',strcat('av',int2str(N2av),'.',ifn,'.tab'));
    nstart=nstart+step;
end
%
fclose(fid1);
fclose all;

