I also like this one, which doesn't require knowledge of how long the set
is:
awk < log.lammps '/Step/ {flag = 1; next}; /Loop time/ {flag = 0}; \
flag {print}' | xmgrace -nxy -
I feel embarrassed to say that I didn't know how to do -nxy and then
read from standard input before reading your message (answer: use - as
the file name); I've always used -pipe before, but that only works with
plain old x-y data.
This will grab everything between lines that match "Step" and lines that
match "Loop time"; the pipe through grep is only necessary because Grace
will be upset that "Step" and similar lines are not numbers. You could,
of course, remove them in awk (but I've already shown how to do that).
The above command is probably easier to remember than my previous example.
I have this code which I wrote a while ago (when I did not know about complex operations using grep, pipe, awk etc.) which does exactly that. It works with both line single and line multi. Please give it a shot if you wish. The basic steps are written in the pdf file. It can read multiple files in a single go and plot the multiple files’ data in parallel, (i.e., independent datasets) or in series (one after other) for a particular quantity of interest. I have written some xmgrace settings within the code which you can modify for the visualization that you feel most comfortable with.
I got it down to one command, though admittedly this takes us back into
the realm of doing something complicated:
sed -n '1,/Step/!{ /Loop time/,/Step/!p; }' outfile | xmgrace -nxy -
Using sed is something I would like to get better at (I usually use it
just for search-and-replace; the above example is something I wouldn't
be able to write without finding the one cited above).
Note that if all you want is xmgrace -nxy, you do not have to strip
out the 'Loop time' and subsequent lines, but for -bxy, you do. But
the above works for both. Extra credit. If you log file contains
multiple runs, each with different thermo output, and you only want to
see, say the third run, how would you do that in awk or sed?
Note that if all you want is xmgrace -nxy, you do not have to strip
out the 'Loop time' and subsequent lines, but for -bxy, you do. But
the above works for both.
Extra credit: If your log file contains multiple runs, each with
different thermo output, and you only want to plot, say, the third
run, how would you do that in awk or sed?
Technically, you do need to strip out the "Loop time" line, but it
generates a warning, not an error, so it's not fatal. Grace is finicky
about the first line, though.
For a journey back into the realm of doing complicated things, try this
(call it "plot-thermo-data"):
#! /bin/awk -f
BEGIN {
if ( stepnum == 0 ) stepnum = 1 # if unset, pick first set of output
print "@xaxis label \"Time Step\""
}
/Step/ {
num += 1
if ( num != stepnum ) next
n = 0
for (i=2; i<=NF; i++) {
print "@s" n, "legend \"" $i "\""
n += 1
}
}
/Step/,/step/ { if ( $0 ~ /[sS]tep/ ) next; else print }
Then this should, if you're using a version of Grace compatible with mine
(I'm using 5.1.23), plot everything and auto-label all the sets and the
x-axis for you:
plot-thermo-data log.lammps | xmgrace -nxy -
Karl D. Hammond
University of Tennessee, Knoxville [email protected]...
"You can never know everything, and part of what you know is always
wrong. A portion of wisdom lies in knowing that. A portion of courage
lies in going on anyway."
"Nothing ever goes as you expect. Expect nothing, and you will not be
surprised."
Thanks for sharing. This is a pretty nice program. Is this building
on your tools/ thermo_extract.c? Would you like to have it added to
the tools directory? Perhaps we should set up a tools/xmgrace folder
that people can add stuff to.
Thanks for the kind words. Yes, it is the second version of that program. If possible, I would like to get the older version get replaced with this one. I would let Steve decide how he wants to include it in the tools directory.