"overwrite" option in "fix ave/time"

Nils,

I have seen this behavior as well. Did you see Steve’s suggestion in an earlier post? Here it is again (below). Can you test his change and see if it fixes the problem (without having to close/open the file each time)?

Thanks,

Stan

Here is Steve’s suggestion:

Maybe the file needs to be truncated in overwrite mode,
in case the new version is shorter than the old.

Try adding the 2nd overwrite if clause in fix_ave_correlate.cpp:

// output result to file

if (fp && me == 0) {
if (overwrite) fseek(fp,filepos,SEEK_SET);
fprintf(fp,BIGINT_FORMAT " %d\n",ntimestep,nrepeat);
for (i = 0; i < nrepeat; i++) {
fprintf(fp,"%d %d %d",i+1,inevery,count[i]);
if (count[i])
for (j = 0; j < npair; j++)
fprintf(fp," %g",prefactor
corr[i][j]/
count[i]);
else
for (j = 0; j < npair; j++)
fprintf(fp," 0.0");
fprintf(fp,"\n");
}
fflush(fp);
if (overwrite) { // add these lines
long fileend = ftell(fp);
ftruncate(fileno(fp),fileend);
}
}

You also need #include “unistd.h” at the top.
If that fixes the issue, I’ll post a patch.

Steve

Hi Stan,

thanks for pointing this out to me. I was just worried about portability. But I think that the unistd header file is supported/provided by most/all unix-based systems. So, that seems to be a good because shorter way to deal with the problem. I tested Steve's suggestion on both a linux cluster in parallel and on my ancient Macbook (serial) with the result that ftruncate does the job properly (i.e., got no additional characters anymore in my RDF time-averaged file).

Cheers,
Nils