Sorry for the probably strangely worded title but I don't really know how else to put it.
Background context: Post processing LAMMPS simulation data.
tl;dr: I'm making two spheres collide, every defined timestep the simulation outputs a bunch of data including total energy of the particles, their coordinates, etc...
Here is my problem:
I'm using awk to post process this data, what I need right now is for it to find the closest point two values approach, give me the closest approach distance (called overlap in the code since it's actually two particles overlapping slightly) and give me the line number that happens on.
So X1 & X2 will first approach each other, reach a closest point then distance themselves from each other.
Finding the closest distance is not a problem.
I do it thus:
The relative code includes the bits with 'overlap' 'max' 'dx' 'z1' 'z2' etc..
The other code is for a similiar problem: Once the energy reaches equilibrium I want that equilibrium and the line where it happens.
However in this case that's not a problem, since it will be the last line treated so FNR is correct.
BEGIN{
oldte=0
te2=1
max=0
OFS="," # Changes Output Field Seperator to a comma (default is space)
# so it can be appended to a .csv file which excel opens without a prompt
printf("%s,%s,%s,%s,%s,%s,%s,\n","Change","Et1","Et2","ColDt","dt","steps","max")
}
{
if((FNR+1)%11==0)
{
te1=$5
z1=$1
}
if(FNR%11==0){
te2=$5
dt=$6
z2=$1
dx=(z2-z1)
overlap=(0.05-dx)
if(overlap>max)
{
max=overlap # overlap calculations
}
if(oldte==te2)
{
steps=FNR/11
colDt=dt*steps
printf("%s,%s,%s,%1.8f,%s,%s,%1.8f\n",change,te1,te2,colDt,dt,steps,max)
exit
}
else
{
oldte=$5
}
}
}
END{
}
So the problem here is that I can't use
ClosestPoint=FNR/11
in the if expression for finding the max value of overlap because when I call that variable to be printed along with the other data, it will be reevaluated and use the FNR at that point in the input file (which will be to far down so to speak).
It's probably a lot more explanation then needed for my question but I thought I'd give as much context as possible.
I guess it just comes down to this:
Can I set a variable X to equal the value of NFR at the time that X is set and not have X be reevaluated when I print it.