next up previous contents index
Next: 6.2.8 history.h Up: 6.2 The NEMO Macro Previous: 6.2.6 vectmath.h   Contents   Index


6.2.7 snapshots: get_snap.c and put_snap.c

These routines exemplify an attempt to provide truly generic I/O of N-body data. They read and write structured binary data files conforming to the overall form seen in earlier sections. Internally they operate on Body structures; A Body has components accessed by macros such as Mass for the mass, Pos and Vel for the position and velocity vectors, etc.. Since get_snap.c and put_snap.c use only these macros to declare and access bodies, they can be used with any suitable Body structure. They are thus provided as C source code to be included in the compilation of a program. Definitions concerning Body's and snapshots are obtained by including the files snapshot/body.h and snaphot/snapshot.h.

A program which should handle a large number of particles, may decide to include a more simple Body structure, as is e.g. provided by the snapshot/barebody.h macro file. This body only includes the masses and phase space coordinates, which would only occupy 28 bytes per particle (in single precision), as opposed to the 100/104 bytes per particle for a double precision Body from the standard snapshot/body.h macro file. This last one contains Mass, PhaseSpace, Phi, Acc, Aux and Key.

In the example listed under Table [*] the first snapshot of an input file is copied to an output file.


Table: $NEMO/src/tutor/snap/snapfirst.c
\begin{table}\small\verbatimlisting{snapfirst.src}
\normalsize\end{table}


Notice that the first argument of stropen(), the filename, is directly obtained from the user interface. The input file is opened for reading, and the output file for writing. Some history6.11is obtained from the input file (would we not have done this, and the input file would have contained history, a subsequent get_snap() call would have failed to find the snapshot), and the first snapshot is read into an array of bodies, pointed to by btab. Then the output file has the old history written to it (although any command line arguments were added to that), followed by that first snapshot. Both files are formally closed before the program then returns.


next up previous contents index
Next: 6.2.8 history.h Up: 6.2 The NEMO Macro Previous: 6.2.6 vectmath.h   Contents   Index
(c) Peter Teuben