How to append file for fix ave/chunk for LAMMPS as a library in FORTRAN

Hello sir,

I am doing a LAMMPS simulation in FORTRAN and i need to run LAMMPS after each iteration of FORTRAN. I am creating a file using fix ave/chunk. But the problem is i need to append it for every iteration of FORTRAN. Otherwise i can not have the data for each FORTRAN iteration. There is any other way of doing it?

Thank you
Adnan

We don’t even know the current way that you are trying to use currently. Your description is very confusing. How about your create a minimal example that demonstrates your problem, so that we can reproduce it and have a closer look.

Sir, Here is the minimal example of the FORTRAN code for LAMMPS as a library. The LAMMPS code is run for 100 iterations of FORTRAN. Here i want to create file “hot.profile” for fix ave/chunk and want this file to append results for 100 iterations of FORTRAN Loop.

Thank you
min_script.f90 (5.7 KB)

This is not what I would call “minimal”. It is a demonstration for excessive use of LAMMPS variables and how they obfuscate and convolute an input and thus make it tedious to understand what it does.

Each loop iteration starts a completely new simulation from scratch. Appending to the ave/chunk output file makes no sense, since the timestep will start from 0 in each iteration and that would make a merged file quite confusing.

What you can do is just have each loop iteration write to a different file (indexed by the loop iteration variable) and then combine those files when post-processing the data for analysis.

Sorry for the mess, Alright sir, Thank for the good advice.

Actually, my original script use of restart file and so it is not starting from zero. In this case if i have an option of appending then it will be good.

To have this option, you will have to modify the source code of fix ave/chunk.

Appending to files is rarely a good idea. If there is any unexpected interruption of the simulation, you are likely to get a corrupted file that may be very difficult to correct. When writing individual files, this is much easier to do and those files can also be easily combined with the “cat” command.

Alright sir, I got it. Thank you.