next up previous contents
Next: 10.3 Performing an experiment Up: 10. A 25-body Example Previous: 10.1 A -body run

10.2 Making gnuplot movies

The next day Alice, Bob, and Carol get together again.

Bob:
Well, Carol, did you do your homework?

Carol:
Sure thing. Here is what I wrote. The first awk script here, split_snapshot1.awk, does what its name suggests: it takes a whole stream of snapshots, and puts it into different files.

Bob:
This means that we can run our integrator nbody_sh1.C and separate all the snapshots that it produces, in order to make a movie in the form of a long row of individual photographs.

Carol:
Yes, that's the idea. Here it is.



\begin{Code}[split\_snapshot1.awk]
\small\verbatiminput{chap10/split_snapshot1.awk} \end{Code}

Bob:
I'm afraid I can't follow the details, since I'm not familiar with awk. I will definitely read up on it, though, since it does seem like a powerful language. Everything is certainly a lot shorter than when you would have written it in C++!

Carol:
Of course, it is a lot slower than C++, but in this case we don't care, because their is not much work involved.

Alice:
But we probably wouldn't want to write an $N$-body integrator in awk, since there speed is of the essence. Though it would be an interesting exercise for Bob, to prove that he has mastered the language $;>)$.

Carol:
Here is my second awk script, makemoviescript1.awk. What it does is to automatically generate all the gnuplot commands for each snapshot. So if we first use split_snapshot1.awk and then makemoviescript1.awk we can watch the movie.



\begin{Code}[makemoviescript1.awk]
\small\verbatiminput{chap10/makemoviescript1.awk} \end{Code}

Bob:
At least I can get the idea, looking at the lines: this handy little script saves a lot of time, automatically generating the gnu plot commands, once a second, while giving you the time to see each frame separately.

Carol:
And to make everything more userfriendly, I even wrote a csh script to invoke both awk scripts in the proper way and order. As you can see, all you have to do is to type makemovie1.csh filename where filename is the name of the output file from the integrator. Here is the script.



\begin{Code}[makemovie1.csh]
\small\verbatiminput{chap10/makemovie1.csh} \end{Code}

Bob:
I can't wait to try it out. May I?

Carol:
Be my guest!

Bob:
Let me try to see first what the command line arguments were for our integrator, by giving it the -h option. I want to switch off all the standard energy error messages, except for the last one. How many particles shall we use?

Alice:
Let's stick with 25, for now.

Bob:
Okay, first we'll do the run.

|gravity> ../chap8/nbody_sh1 -h
usage: ../chap8/nbody_sh1 [-h (for help)] [-d step_size_control_parameter]
         [-e diagnostics_interval] [-o output_interval]
         [-t total_duration] [-i (start output at t = 0)]
         [-x (extra debugging diagnostics)]
|gravity> ../chap9/sphere -n 25 | ../chap8/nbody_sh1 -e 10 > nbody1.out
seed = 1064696533
Starting a Hermite integration for a 25-body system,
  from time t = 0 with time step control parameter dt_param = 0.03  until time 10 ,
  with diagnostics output interval dt_dia = 10,
  and snapshot output interval dt_out = 1.
at time t = 0 , after 0 steps :
  E_kin = 0 , E_pot = -0.576237 , E_tot = -0.576237
                absolute energy error: E_tot - E_init = 0
                relative energy error: (E_tot - E_init) / E_init = -0
at time t = 10 , after 81537 steps :
  E_kin = 0.617884 , E_pot = -1.19413 , E_tot = -0.576245
                absolute energy error: E_tot - E_init = -7.40051e-06
                relative energy error: (E_tot - E_init) / E_init = 1.28428e-05
|gravity>

Bob:
Not bad, a relative energy error of about one part in a hundred thousand. Now let's see whether Carol is a good movie director!


next up previous contents
Next: 10.3 Performing an experiment Up: 10. A 25-body Example Previous: 10.1 A -body run
The Art of Computational Science
2004/01/25