% Complete documentation on the extended LaTeX markup used for Python
% documentation is available in ``Documenting Python'', which is part
% of the standard documentation for Python.  It may be found online
% at:
%
%     http://www.python.org/doc/current/doc/doc.html

\documentclass{manual}
\usepackage{graphicx}

\title{pNbody}

\author{Yves Revaz}

% Please at least include a long-lived email address;
% the rest is at your discretion.
\authoraddress{
	Ecole Polytechnique Fédérale de Lausanne (EPFL) \\
	Laboratory of Astrophysics \\
	51. Ch. des Maillettes \\
	1290 Sauverny\\
	Switzerland\\
	Email: \email{yves.revaz@epfl.ch}
}

\date{February 2008}		% update before release!
				% Use an explicit date so that reformatting
				% doesn't cause a new date to be used.  Setting
				% the date to \today can be used during draft
				% stages to make it easier to handle versions.

\release{4.0}			% release version; this is used to define the
				% \version macro

\makeindex			% tell \index to actually write the .idx file
\makemodindex			% If this contains a lot of module sections.


\begin{document}

\maketitle

% This makes the contents more accessible from the front page of the HTML.
\ifhtml
\chapter*{Front Matter\label{front}}
\fi

%\input{copyright}
\cleardoublepage

\begin{abstract}

\noindent
\class{pNbody} is a parallelized python module toolbox desinged to manipulate and display
interactively very lage N-body systems.

Its oriented object aproche allows the user to perform complicate manipulation
with only very few commands.

As python is an interpreted language, the user can load an N-body system and explore
it interactively using the python interpreter. pNbody may also being used in
python scripts.

The module also contains graphical facilities desinged to create maps of physical
values of the system, like density maps, temperture maps, velocites maps, etc.
Stereo capabilities are also implemented.

pNbody is not limited by file format. Each user may redefine in a parameter file
how to read its specific format.

Its new parallel (mpi) facilities make it works on computer cluster without being limitted
by memery consumption. It has already been tested with 268 millions of particles.



%This python module is designed to manipulate very large N-body data using mpi. 
%From a given model, it allows to extract and plot physical values like energy, 
%kinetic momentum, inertial momentum, centrer of mass etc.
%It also allows to modify the data, selecticting subsystem or merge different models.
%With the associated program \bfcode{gwin}, the user can visualise the data interactively. 
%A huge diversity of mapping of the model are possible, like surface density map, velocity map, 
%velocity dispersion map, etc. 
%Films of evolving data can be computed with \bfcode{mkgmov} and visalized
with \bfcode{gmov}.
\end{abstract}

\cleardoublepage

\tableofcontents

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Overview}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\class{pNbody} is a parallelized python module toolbox desinged to manipulate and display
interactively very lage N-body systems.

Its oriented object aproche allows the user to perform complicate manipulation
with only very few commands.

As python is an interpreted language, the user can load an N-body system and explore
it interactively using the python interpreter. pNbody may also being used in
python scripts.

The module also contains graphical facilities desinged to create maps of physical
values of the system, like density maps, temperture maps, velocites maps, etc.
Stereo capabilities are also implemented.

pNbody is not limited by file format. Each user may redefine in a parameter file
how to read its specific format.

Its new parallel (mpi) facilities make it works on computer cluster without being limitted
by memery consumption. It has already been tested with 268 millions of particles.



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Installation (linux only)}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Prerequiste}

The basic module of pNbody  needs python and additional packages :

\begin{enumerate}

\item Python 2.5 or higher \\
\texttt{http://www.python.org}

\item numpy-1.0.4) or higher \\
\texttt{http://numpy.scipy.org/}

\item Imaging 1.1.5 or higher \\
\texttt{http://www.pythonware.com/products/pil/}

\item Python megawidgets 1.2 or higer (only usefull for some graphics capabilities)\\
\texttt{http://pmw.sourceforge.net/}

%\item Gtools-1.0 \\
%\texttt{http://aramis.obspm.fr/~revaz/Gtools/}

%\item pyfits \\
%\texttt{http://www.stsci.edu/resources/software_hardware/pyfits}

\end{enumerate}

For the parallel capabilities, an mpi distribution is needed (lam,mpich) as well as the
additional python mpi wrapping:

\begin{enumerate}
\item mpi4py \\
\texttt{http://cheeseshop.python.org/pypi/mpi4py}
\end{enumerate}


In order to convert movies in standard format (gif or mpeg), the two 
following applications are needed :
\begin{enumerate}
\item \program{convert}
\item \program{ppmtompeg}
\end{enumerate}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Installing from tarball}

First, uncrompress the distribution file~:
\begin{verbatim}
tar -xzf pNbody-4.0.tgz
cd pNbody-4.0
\end{verbatim}

Now, depending on your python installation you have to be root.
The module is compiled and installed with the following command~:
\begin{verbatim}
python setup.py install
\end{verbatim}
Be sure that \texttt{python} is the executable you want to use with
\class{pNbody}.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Test installation}

To test the installation, go to the example directory 
\texttt{PYTHON\_DIRECTORY/site-packages/pNbody/examples}, where \texttt{PYTHON\_DIRECTORY}
is the directory of your python installation and usually looks like \texttt{/usr/lib/pythonx.y/}.
Then ,simply type :

\begin{verbatim}
python testall.py
\end{verbatim}





%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Default configuration}

De default configuration files are stored in the directory 
\texttt{PYTHON\_DIRECTORY/site-packages/pNbody/config}, where \texttt{PYTHON\_DIRECTORY}
is the directory of your python installation and usually looks like \texttt{/usr/lib/pythonx.y/},
where the \texttt{x.y} corresponds to your python version.

It is recommanded that the user copy in \texttt{~/.pNbody} the content of this default directory, in 
order to have its own configurations files.

The content of the \texttt{config} directory is~:
\begin{tableiii}{l|l|l}{}{\var{parameter}}{Type}{Meaning}
\lineiii{\texttt{formats}}{directory}{this directory contains specific class definition files used to read different formats}
\lineiii{\texttt{rgb_tables}}{directory}{this directory contains all colors tables accessibles by \class{pNbody}}
\lineiii{\texttt{defaultparameters}}{file}{this file contains the default graphical parameters used by \class{pNbody}}
\lineiii{\texttt{unitsparameters}}{file}{this file contains the default units parameters used by \class{pNbody}}
\hline									    
\end{tableiii}	



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Documentation and examples}

Documentation of the package in postcript form is available in the directory \texttt{doc} of
the root instalation directory.

In order to test examples proposed in the tutorial, you are advised to copy the whole 
\texttt{examples} directory somewere in you own directories.
In this document, each time an example (script or commands) is proposed, we assume
that the user is in the \texttt{examples} directory.



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Tutorial}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\class{pNbody} may be used either interactively (in this case, the parallel capabilities are 
yet not available) in the python console, either in scripts. 
Interactive parallel capabilities are available using the \bfcode{gdisp} application described 
later in this document.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Using \class{pNbody} with the python interpreter}

In this section, we assume that \class{pNbody} in installed in 
\texttt{/usr/lib/python2.4/site-packages/pNbody/}. First, copy the \texttt{examples} directory
(\texttt{/usr/lib/python2.4/site-packages/pNbody/examples})
somewere in you own directories and start python~:
\begin{verbatim}
[lunix@lunix ~]$ cd examples
[lunix@lunix examples]$ python
Python 2.4.2 (#2, Jul 13 2006, 15:26:48)
[GCC 4.0.1 (4.0.1-5mdk for Mandriva Linux release 2006.0)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>  
\end{verbatim}
Now, you can load the \class{pNbody} module~:
\begin{verbatim}
>>> from pNbody import *
\end{verbatim}
We can first start by creating a default \class{pNbody} objet and get info about it~:
\begin{verbatim}
>>> nb = Nbody()
>>> nb.info()
-----------------------------------
particle file    : ['file.dat']
ftype            : 'Nbody_default'
nbody            : 0
nbody_tot        : 0
npart            : array([0])
npart_tot        : array([0])
mass_tot         : 0.0
byteorder        : 'little'
pio              : 'no'
\end{verbatim}
All variables linked to the object \var{nb} are accesible by typing \var{nb.} followed
by the associated variables~:
\begin{verbatim}
>>> nb.nbody
0
>>> nb.mass_tot
0.0
>>> nb.pio
'no'
\end{verbatim}

Now, you can create an object by giving the positions of particles~:
\begin{verbatim}
>>> pos = ones((10,3),float32)
>>> nb = Nbody(pos=pos)
>>> nb.info()
-----------------------------------
particle file       : ['file.dat']
ftype               : 'Nbody_default'
mxntpe              : 6
nbody               : 10
nbody_tot           : 10
npart               : array([10,  0,  0,  0,  0,  0])
npart_tot           : array([10,  0,  0,  0,  0,  0])
mass_tot            : 1.00000011921
byteorder           : 'little'
pio                 : 'no'

len pos             : 10
pos[0]              : array([ 1.,  1.,  1.], dtype=float32)
pos[-1]             : array([ 1.,  1.,  1.], dtype=float32)
len vel             : 10
vel[0]              : array([ 0.,  0.,  0.], dtype=float32)
vel[-1]             : array([ 0.,  0.,  0.], dtype=float32)
len mass            : 10
mass[0]             : 0.10000000149
mass[-1]            : 0.10000000149
len num             : 10
num[0]              : 0
num[-1]             : 9
len tpe             : 10
tpe[0]              : 0
tpe[-1]             : 0
\end{verbatim}
In this case, you can see that the class automatically intitialize other arrays
variables (\var{vel}, \var{mass}, \var{num} and \var{rsp})
with default values. Only the first and the last element of each defined vector are displyed
by the methode \var{info}.
All defined arrays and array elements may be easily accessible using the \class{numarray} convensions.
For exemple, to display and change the positions of the tree first particles, type~:
\begin{verbatim}
>>> nb.pos[:3]
array([[ 1.,  1.,  1.],
       [ 1.,  1.,  1.],
       [ 1.,  1.,  1.]], type=float32)
>>> nb.pos[:3]=2*ones((3,3),float32)
>>> nb.pos[:3]
array([[ 2.,  2.,  2.],
       [ 2.,  2.,  2.],
       [ 2.,  2.,  2.]], type=float32)
\end{verbatim}

Now, lets try to open the gadget snapshot \texttt{gadget_z00.dat}. 
This is achieved by typing :
\begin{verbatim}
>>> nb = Nbody('gadget_z00.dat',ftype='gadget')
\end{verbatim}
Again, informatins on this snapshot may be obtained using the instance \var{info()}~:
\begin{verbatim}
>>> nb.info()
-----------------------------------
particle file       : ['gadget_z00.dat']
ftype               : 'Nbody_gadget'
mxntpe              : 6
nbody               : 20560
nbody_tot           : 20560
npart               : array([ 9160, 10280,     0,     0,  1120,     0])
npart_tot           : array([ 9160, 10280,     0,     0,  1120,     0])
mass_tot            : 79.7066955566
byteorder           : 'little'
pio                 : 'no'

len pos             : 20560
pos[0]              : array([-1294.48828125, -2217.09765625, -9655.49609375], dtype=float32)
pos[-1]             : array([ -986.0625    , -2183.83203125,  4017.04296875], dtype=float32)
len vel             : 20560
vel[0]              : array([ -69.80491638,   60.56475067, -166.32981873], dtype=float32)
vel[-1]             : array([-140.59715271,  -66.44669342,  -37.01613235], dtype=float32)
len mass            : 20560
mass[0]             : 0.00108565215487
mass[-1]            : 0.00108565215487
len num             : 20560
num[0]              : 21488
num[-1]             : 1005192
len tpe             : 20560
tpe[0]              : 0
tpe[-1]             : 4

atime               : 1.0
redshift            : 2.22044604925e-16
flag_sfr            : 1
flag_feedback       : 1
nall                : [ 9160 10280     0     0  1120     0]
flag_cooling        : 1
num_files           : 1
boxsize             : 100000.0
omega0              : 0.3
omegalambda         : 0.7
hubbleparam         : 0.7
flag_age            : 0
flag_metals         : 0
nallhw              : [0 0 0 0 0 0]
flag_entr_ic        : 0
critical_energy_spec: 0.0

len u               : 20560
u[0]                : 6606.63037109
u[-1]               : 0.0
len rho             : 20560
rho[0]              : 7.05811936674e-11
rho[-1]             : 0.0
len rsp             : 20560
rsp[0]              : 909.027587891
rsp[-1]             : 0.0
len opt             : 20560
opt[0]              : 446292.5625
opt[-1]             : 0.0
\end{verbatim}
You can obtain informations on physical values, like the center of mass or
the total angular momentum vector by typing~:
\begin{verbatim}
>>> nb.cm()
array([-1650.15307617,   610.07275391, -1689.27880859], dtype=float32)
>>> nb.Ltot()
array([-1112078.125 ,  -755964.1875, -1536667.125 ], dtype=float32)
\end{verbatim}
In order to visualise the model in position space, it is possible to generate a surface 
density map of it using the \var{display} instance~:
\begin{verbatim}
>>> nb.display(size=(10000,10000),shape=(256,256),palette='light')
\end{verbatim}
You can now performe some operations on the model in order to explore a specific region.
First, translate the model in position space~:
\begin{verbatim}
>>> nb.translate([3125,-4690,1720])
>>> nb.display(size=(10000,10000),shape=(256,256),palette='light')
>>> nb.display(size=(1000,1000),shape=(256,256),palette='light')
\end{verbatim}
Ou can now rotate around 
\begin{verbatim}
>>> nb.rotate(angle=pi)
>>> nb.display(size=(1000,1000),shape=(256,256),palette='light')
\end{verbatim}
You can now  display a temperature map of the model. First, create a new object
with only the gas particles.
\begin{verbatim}
>>> nb_gas = nb.select('gas')
>>> nb_gas.display(size=(1000,1000),shape=(256,256),palette='light')
\end{verbatim}
now, display the temperture mass-weighted map~:
\begin{verbatim}
>>> nb_gas.display(size=(1000,1000),shape=(256,256),palette='rainbow4',mode='T',filter_name='gaussian')
\end{verbatim}
You can select only particles within a radius smaller tha 500 (in user units) with respect to the center
\begin{verbatim}
>>> nb_sub = nb.selectc((nb.rxyz()<500))
>>> nb_sub.display(size=(1000,1000),shape=(256,256),palette='light')
\end{verbatim}
Now, rename the new model and save it.
\begin{verbatim}
>>> nb_sub.rename('gadget_z00_sub.dat')
>>> nb_sub.write()
\end{verbatim}
A new gadget file has been created and saved in the current directory.
We can now select particles as a function of the temperature. First, display
the maximum temperature among all gas particles, then selectc particles and finally save
in '\texttt{T11.num}' the identifier (variable \texttt{num}) of these particles.
\begin{verbatim}
>>> log10(max(nb_gas.T()))
12.8707923889
>>> nb_sub = nb_gas.selectc( (nb_gas.T()>1e11) )
>>> nb_sub.write_num('T11.num')
\end{verbatim}
Now open a new snapshot, from the same simulation, but at different redshift and find the particles in 
previous snapshot with temperature higher than $10^{11}$:
\begin{verbatim}
>>> nb = Nbody('gadget_z40.dat',ftype='gadget')
>>> nb.display(size=(10000,10000),shape=(256,256),palette='light')
>>> nb_sub = nb.selectp(file='T11.num')
>>> nb_sub.display(size=(10000,10000),shape=(256,256),palette='light')
\end{verbatim}

Now, instead of saving it in a gadget file, save it in a binary file type. You simply need
to call the \var{set_ftype} instance before saving it~:
\begin{verbatim}
>>> nb = nb.set_ftype('binary')
>>> nb.rename('binary.dat')
>>> nb.write()
\end{verbatim}

As a last example, we show how two \class{pNbody} models can be easyly merged with only 11 lines.
\begin{verbatim}
>>> nb1 = Nbody('disk.dat',ftype='gadget')
>>> nb2 = Nbody('disk.dat',ftype='gadget')
>>> nb1.rotate2(angle=pi/4,axis=[0,1,0])
>>> nb1.translate([-150,0,0])
>>> nb1.vel = nb1.vel + [50,0,0]
>>> nb2.rotate(angle=pi/4,axis=[1,0,0])
>>> nb2.translate([+150,0,50])
>>> nb2.vel = nb2.vel - [50,0,0]
>>> nb3 = nb1 + nb2
>>> nb3.rename('merge.dat')
>>> nb3.write()
\end{verbatim}
Now display the result from different point of view~:
\begin{verbatim}
>>> nb3.display(size=(300,300),shape=(256,256),palette='lut2')
>>> nb3 = nb3.select('disk')
>>> nb3.display(size=(300,300),shape=(256,256),palette='lut2',view='xz')
>>> nb3.display(size=(300,300),shape=(256,256),palette='lut2',view='xy')
>>> nb3.display(size=(300,300),shape=(256,256),palette='lut2',view='yz')
>>> nb3.display(size=(300,300),shape=(256,256),palette='lut2',xp=[-100,0,0])
\end{verbatim}
or save it into a gif file~:
\begin{verbatim}
>>> nb3.display(size=(300,300),shape=(256,256),palette='lut2',xp=[-100,0,0],save='image.gif')
\end{verbatim}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Using pNbody with scripts}

Instead of using \class{pNbody} in the python interpreter, it is very usefull to use \class{pNbody} in scripts. Usually
a python script begin by the line \texttt{\#!/usr/bin/env python} and must be executable (\texttt{chmod a+x file.py}).
As an example (\texttt{slice.py}), we show how to write a script that opens a gadget file, select gas and cut a thin
slice ($-1000<y<1000$). The new files are saved using the extention \texttt{.slice}.
\begin{verbatim}
#!/usr/bin/env python

import sys
from pNbody import *

files = sys.argv[1:]

for file in files:
  print "slicing",file
  nb = Nbody(file,ftype='gadget')
  nb = nb.select('gas')  
  nb = nb.selectc((fabs(nb.pos[:,1])<1000))
  nb.rename(file+'.slice')
  nb.write()
\end{verbatim}

You can run this script with the command 
\begin{verbatim}
[lunix@lunix ~]$ ./scripts/slice.py gadget_z*0.dat
\end{verbatim}
or
\begin{verbatim}
[lunix@lunix ~]$ python ./scripts/slice.py gadget_z*0.dat
\end{verbatim}

In the current version of \class{pNbody}, scripts may also be used in parallel, if \texttt{mpi}
and \texttt{mpi4py} is installed.
In this case, run the script with a command like (depending of your mpi implementation):
\begin{verbatim}
[lunix@lunix ~]$ mpirun -np 2 slice.py gadget_z*0.dat
\end{verbatim}
In this script only the processus of rank 0 open the file. It then broadcast the particles 
among all the other processors. 
The selection of gas and the slice are preformed by all processors.
Finally, the \texttt{nb.write()} command will gather all particles and write the output file.

Instead of opening one file and writing another, one can ask that every processus open one file
and write one. First, modify the previous script by adding the command \texttt{nb.set_pio('yes')}
The script \texttt{split.py} demonstrate this capabilites.
\begin{verbatim}
#!/usr/bin/env python

import sys
from pNbody import *

files = sys.argv[1:]

for file in files:
  nb = Nbody(file,ftype='gadget')
  nb.set_pio('yes')	# enable parallel input/output
  nb.write()
\end{verbatim}
and run
\begin{verbatim}
[lunix@lunix ~]$ mpirun -np 2  ./scripts/split.py gadget_z*0.dat
\end{verbatim}
Every file is opened by the processus of rank 0, but now, during the \texttt{nb.write} command
every processus writes its own file. The files have the same
name than the name given in \texttt{Nbody()} with an extention \texttt{.i} where \texttt{i} corresponds to
the processus rank. 

Now that you have created two output, try to read them.
In the script \texttt{slice.py}, add a \texttt{pio='yes'} in the
object argument.
\begin{verbatim}
#!/usr/bin/env python

import sys
from pNbody import *

files = sys.argv[1:]

for file in files:
  print "slicing",file
  nb = Nbody(file,ftype='gadget',pio='yes')
  nb = nb.select('gas')  
  nb = nb.selectc((fabs(nb.pos[:,1])<1000))
  nb.rename(file+'.slice')
  nb.write()
\end{verbatim}
and run~:
\begin{verbatim}
[lunix@lunix ~]$ mpirun -np 2  ./scripts/slice2.py gadget_z*0.dat
\end{verbatim}

Now, the script works fully in parallel. Every processus reads, writes and works on its own file, correspondig
to a subset of the total number of particles. 

Lets try two other scripts. The first one try to find the radial maximum distance among all particles
and the center. It illustrate the difference between using \texttt{max()} wich gives the local maximum (maximum among
particles of the node) and \texttt{mpi.mpi_max()} which gives the global maximum among all particles. 
\begin{verbatim}
#!/usr/bin/env python

import sys
from pNbody import *

file = sys.argv[1]

nb = Nbody(file,ftype='gadget',pio='yes')
local_max  = max(nb.rxyz())
global_max = mpi.mpi_max(nb.rxyz())

print "proc %d local_max = %f global_max = %f"%(mpi.ThisTask,local_max,global_max)
\end{verbatim}
When running it, you should get ~:
\begin{verbatim}
[lunix@lunix examples]$ mpirun -np 2 ./scripts/findmax.py gadget_z00.dat
proc 0 local_max = 12070.458008 global_max = 12757.492188
proc 1 local_max = 12757.492188 global_max = 12757.492188
\end{verbatim}
which illustrate clearly the point.
Finally, the latter script shows that even graphical functions support parallelisme.
The script \texttt{showmap.py} illustrate this point by computing a map of the model~:
\begin{verbatim}
#!/usr/bin/env python

import sys
from pNbody import *

file = sys.argv[1]

nb = Nbody(file,ftype='gadget',pio='yes')
nb.display(size=(10000,10000),shape=(256,256),palette='light')
\end{verbatim}
When running~:
\begin{verbatim}
[lunix@lunix examples]$ mpirun -np 2 ./scripts/showmap.py gadget_z00.dat
\end{verbatim}
you get an image of the model.




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Using \class{pNbody} interactively in parallel}

\texttt{mpi4py} does not currently works with the standard python interpreter. This prevents us
to works whith models interactively in parallel.
However, using \bfcode{gwin}, while displaying your model in a window, you can interact with it in
parallel. Try to run~(here, we assume you are using mpich-2 as mpi implementation):
\begin{verbatim}
[lunix@lunix examples]$ mpirun -np 2 gwin -t gadget gadget_z00.dat
\end{verbatim}
A window opens, displaying a map of your model. 
%
	\begin{figure}
	\begin{center}
	\includegraphics[width=14cm]{graph/gwin1.ps}
	\caption{Snapshot of gwin.}
	\label{pginw1}
	\end{center}
	\end{figure}
%	
With your mouse, you can interact with the model. 
While pressing the left button of your mouse, move it on the map. The red axis at the center
moves and determines the observer orientation.
A right click redisplays the model. 
You will find a more complete documentation of \bfcode{gwin} futher in this document. 
Here, weonly focus on some parallel features.
Try \texttt{node info} on the \texttt{Operations} menu. You get the number of particles contained
by each processus as well as the number particles of each type.
Now, we can interact with the model using the bottom entry, at the left of the \texttt{clear} button.
The commands you can entrer here are similar to the one used in the python console or in python scripts. 
The only (but major difference) is that the variable representing the model object is called
\texttt{self.nb} instead of \texttt{nb}.
Try for example~:
\begin{verbatim}
self.nb.translate([3125,-4690,1720])
\end{verbatim}
and then press the right button of the mouse. The model is now center on $(-3125,4690,-1720)$.
Now select a small region around this point~:
\begin{verbatim}
self.nb = self.nb.selectc((self.nb.rxyz()<500))
\end{verbatim}
Now, if you display the number of particles per processus, using \texttt{node info} on the \texttt{Operations} menu,
you probably see processus with much more particles.
You can redistribute the number of particles in order to increase the preformaces, with the command
\texttt{redistribute particles} on the \texttt{Operations} menu.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Minimal \class{pNbody} object}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

A minimal \class{pNbody} object consists of a set of 4 numarray vectors~:
\begin{itemize}
\item \var{pos}: 	positions of particles ($n\times 3$ float32 Numeric array)
\item \var{vel}: 	velocities of particles ($n\times 3$ float32 Numeric array)
\item \var{mass}: 	mass of particles ($n$ Float Numeric array)(default=None)
\item \var{num}: 	identifier of particles ($n$ Int Numeric array)(default=None)
\end{itemize}

and a set of default associated variables~:

\begin{itemize}
\item \var{npart}: 	number of particles of each type (List), for the current node.
\item \var{nbody}:      number of particles for the current node (sum of \var{npart})
\item \var{npart_tot}:  number of particles of each type (List), summing over all nodes.
\item \var{nbody_tot}:  total number of particles (sum of \var{npart_tot})
\item \var{mass_tot}:   total mass of the system
\end{itemize}

The variable \var{npart} gives the list of particles of each type. For example
\begin{verbatim}
>>> nb.npart
array([10, 20,  0, 10])
\end{verbatim}
means that there are 4 particle types, 
10 particles belongs to the first type,
20 to the second,
0 to the third
and 10 to the fourth.

The value of the following variables are automatically set during intitialisation (using 
the values of \var{npart},\var{nbody} and \var{nb.mass}), 
even if they are defined before (during the reading process)~:

\begin{itemize}
\item \var{nbody} :
\item \var{npart_tot} : \texttt{\textbf{get_npart_tot()}}  
\item \var{nbody_tot} : \texttt{\textbf{get_nbody_tot()}}
\item \var{mass_tot}  : \texttt{\textbf{get_mass_tot()}}
\end{itemize}


%Other variables gives supplementary info~:
%
%\begin{itemize}
%\item \var{p_name}: 	name of the file or list of files containing the data (string or list of strings)
%\item \var{ftype}: 	name of the file or list of files containing the data (string or list of strings)
%\item \var{status}: 	status of the file, \var{"new"} or \var{"old"} (default=\var{"old"})
%\item \var{byteorder}:  byte order "littelendian" or "bigendian" (default=sys.byteorder)
%\item \var{pio}:        parallel input/output (default="no")
%\item \var{log}:        pointer to log ouput object (default=None)
%\end{itemize}


The user is free, when reading a specific file format, to add specific variables (for example, the time of 
the snapshot) and specific numarray vectors (density, specific energy, etc.).
See the formats section for more details.



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Formats}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Thanks to the interpreted facilities of python, \class{pNbody} may read any file format. You
simply have to decribe it in a python file placed in your \texttt{~/.Nbody/formats} directory.
This python file declares a new class that inherit all atributes of the default \class{pNbody} class.

As an example, we will describe here after, how to write a file that reads the format
written by the following Fortan instructions~:

\begin{verbatim}
  INTEGER	  NBODY,NGAS,NSTARS
  REAL*4	  TNOW
  REAL*4	  POS(3,MXBODY),VEL(3,MXBODY),MAS(MXBOFY), MET(MXBOFY)
  INTEGER	  K,P	  

  OPEN (UNIT=1,FILE='simpleformat.dat',FORM='UNFORMATTED', STATUS='UNKNOWN')
  WRITE (1) TNOW,NGAS,NSTAR
  WRITE (1) ((POS(K,P), K=1,3),P=1,NBODY)
  WRITE (1) ((VEL(K,P), K=1,3),P=1,NBODY)
  WRITE (1) (MAS(P),	       P=1,NBODY)
  WRITE (1) (MET(P),	       P=1,NGAS)
  CLOSE(UNIT=1)
\end{verbatim}

The file consists of a header block (\texttt{TNOW},\texttt{NGAS},\texttt{NSTAR}),
a position block of size 3 \texttt{NBODY},
a velocity block of size 3 \texttt{NBODY}, 
a mass block of size \texttt{NBODY} and
a metallicity block of size \texttt{NGAS}.



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Some init}


In order to read this file, we have to create a format file : \texttt{~/.Nbody/formats/simpleformat.py}.
First add the following lines that tells \class{pNbody} which functions to use when reading and
writing a file. Here, the functions will be \texttt{self.read_particles} and \texttt{self.write_particles}.
 
\begin{verbatim}

class Nbody_simpleformat(NbodyDefault):
  
  def get_read_fcts(self):
    return [self.read_particles]
    
  def get_write_fcts(self):
    return [self.write_particles]    

\end{verbatim}

Now, if you need it, specify specific variables and their default values, 
with the function \texttt{get_spec_vars}

\begin{verbatim}    
  def get_spec_vars(self):
    '''
    return specific variables default values for the class
    '''
    return {'tnow'   :0.,
            'ngas'   :0,
            'nstars' :0
	    }
\end{verbatim}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{The read function}


Now, its time to write the \texttt{read_particles} functions. 

\begin{verbatim}
  def read_particles(self,f):
 
    tpl = (float32,int32,int32)
    tnow, ngas, nstar = io.ReadBlock(f,tpl,byteorder=self.byteorder,pio=self.pio)
\end{verbatim}
    
The variable \var{tpl} describe the type of the data contained in the header,
then, use the function \texttt{\textbf{io.ReadBlock()}} to read the header and 
send it to other nodes, if necessary (if \var{self.pio}='no'). 
    
Now, before reading the vectors blocks, we have to define how particles, depending on their
type, will be distributed among nodes.
First, create the \var{npart_read} particle, that corresponds to \var{npart} read from the header.
Then simply use \texttt{\textbf{get_npart_and_npart_all()}} to create \var{npart} and \var{npart_all}.
\var{npart} gives you the number of particles of each type present in the local node.
\var{npart_all} is a list of \var{npart} corresponding to all nodes.
Thanks to this latter variable, the \texttt{\textbf{io.ReadArray()}} function will be able to
read data blocks and send the right particles to the right nodes, taking into account the type
of the particles.
\begin{verbatim}        
    npart_read = array([ngas,nstar])
    npart,npart_all       = self.get_npart_and_npart_all(npart_read)
\end{verbatim} 
Now, as the metallicity block contains informations only for gas particles, we have to compute
an equivalent of \var{npart_all} but only for the first type.
\begin{verbatim} 
    npartgas,npartgas_all = self.get_npart_and_npart_all(npart_read[0])
\end{verbatim} 

Now, it is usefull to compute the specific local variables \var{ngas},\var{nstar} and \var{nbody}.

\begin{verbatim}     
    # now, get the corect values
    ngas  = npart[0]
    nstar = npart[1]
    nbody = sum(npart)
\end{verbatim} 

It is time now to read the position, velocities, mass and metallicity blocks, by giving to the
function \texttt{\textbf{io.ReadArray()}} the right particle distribution (\var{npart_all} or \var{npartgas_all}).
The \texttt{self.} in front of the variables is important to make these vectors global.
In the last line, we complete the vector \var{self.meta} by adding zeros, in order to have a value
for each particles (even for stars).

\begin{verbatim}            		
    self.pos = io.ReadArray(f,float32,shape=(nbody,3),byteorder=self.byteorder,pio=self.pio,nlocal=npart_all)
    self.vel = io.ReadArray(f,float32,shape=(nbody,3),byteorder=self.byteorder,pio=self.pio,nlocal=npart_all)
    self.mass= io.ReadArray(f,float32,                byteorder=self.byteorder,pio=self.pio,nlocal=npart_all)
    self.meta= io.ReadArray(f,float32,                byteorder=self.byteorder,pio=self.pio,nlocal=npartgas_all)
    self.meta  = concatenate((self.meta,zeros(nbody-npart[0]).astype(float32)))
\end{verbatim} 

Finally, invoce the two following commands to ensure that all variables will be accessible in the main class.
\begin{verbatim}
    self.make_default_variables_global(vars())
    self.make_specific_variables_global(vars())
\end{verbatim}     
    

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{The write function}

The \texttt{write_particles} functions begins to gather all npart.
Then depending if we will write in parallel (\var{self.pio} = 'yes') or not,
we have to reduce or not the values of \var{ngas} and \var{nstar}. This is important
to write a consistent header.

\begin{verbatim}
  def write_particles(self,f):

    npart_all = array(mpi.mpi_Allgather(self.npart))
    
    if self.pio == 'yes':
      ngas  = self.ngas
      nstar = self.nstar
    else:
      ngas  = mpi.mpi_reduce(self.ngas)
      nstar = mpi.mpi_reduce(self.nstar)
\end{verbatim}
The header is written with the function \texttt{\textbf{io.WriteBlock()}} using the
variables \var{tpl} telling what to write with wich format.

\begin{verbatim}
    tpl = ((self.tnow,float32),(ngas,int32),(nstar,int32))
    io.WriteBlock(f,tpl,byteorder=self.byteorder)																																		   
\end{verbatim}    

And finally, write the vectors, using the function \texttt{\textbf{io.WriteArray()}}

\begin{verbatim} 	
    io.WriteArray(f,self.pos.astype(float32),byteorder=self.byteorder,pio=self.pio,nlocal=npart_all)																												   
    io.WriteArray(f,self.vel.astype(float32),byteorder=self.byteorder,pio=self.pio,nlocal=npart_all)
    io.WriteArray(f,self.mass.astype(float32),byteorder=self.byteorder,pio=self.pio,nlocal=npart_all)																												   
    io.WriteArray(f,self.meta[:self.npart[0]].astype(float32),byteorder=self.byteorder,pio=self.pio,nlocal=npart_all)
\end{verbatim} 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Adding specific functions to the class}


Here we describe how we can add specific functions to the new class defined in \texttt{simpleformat.py}.
This may be usefull if you want for example to get specific informations on the class.
You can simplay redefine the \texttt{\textbf{spec_info()}} functions that is called automatically by the 
\texttt{\textbf{info()}}.

\begin{verbatim} 
  def spec_info(self):
    """
    Write spec info
    """	
    infolist = []
    infolist.append("")
    infolist.append("tnow                : %s"%self.tnow)	
    infolist.append("ngas                : %s"%self.ngas)
    infolist.append("nstar               : %s"%self.nstar)		
    return infolist  
\end{verbatim}

Other functions may be defined, for example, a function that simplay return the metallicity of
each particles.

\begin{verbatim}
  def Metallicity(self):
    """
    Return the metallicity
    """	
    return self.meta  
\end{verbatim}

With this function, you can easilly display the metallicity value of each particles in a plot, witout
redefining anything else (See further).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Example}

Try :
\begin{verbatim}
[lunix@lunix ~/examples]$ gwin -t simpleformat simpleformat.dat
\end{verbatim}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Parameters}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

The module \class{pNbody} uses two sets of parameters. Default values for these parameters are
stored in two files : \texttt{~/.Nbody/defaultparameters} (display parameters) and 
\texttt{~/.Nbody/unitsparameters} (units parameters).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Display parameters}\label{displayparameters}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

The list and the meaning of display parameters is given in the following table~:

\begin{tableiii}{l|l|l}{}{\var{parameter}}{Type}{Meaning}
\lineiii{obs}{ArrayObs}{Observer matrix}
\lineiii{xp}{List}{Observing position}
\lineiii{x0}{List}{Position of observer}
\lineiii{alpha}{Float}{Angle of head}
\lineiii{view}{String}{Projection ("xy","yz","xz")}    
\lineiii{r_obs}{Float}{Distance to the observer}
\hline
\lineiii{eye}{String}{Name of the eye ("left" or "right") (stereo mode)}
\lineiii{dist_eye}{Float}{Distance between the eyes (stereo mode)}
\lineiii{foc}{Float}{Focal distance (stereo mode)}
\hline
\lineiii{persp}{String}{"on"=frustum projection "off"=orthogonal projection}
\lineiii{clip}{Tuple}{Clip plane (near,far)}
\lineiii{cut}{String}{Remove particles outisde clip plane ("yes" or "no")}
\hline
\lineiii{shape}{Tuple}{Shape of the image in pixels (nw,nh)}
\lineiii{size}{Tuple}{Physical half size of the image (dx,dy)}
\hline
\lineiii{space}{String}{Working space, "pos"=position space "vel"=velocity space}
\lineiii{mode}{String}{Physical value to plot}
\hline
\lineiii{frsp}{Float}{Factor for gas smoothing}
\lineiii{filter_name}{String}{Name of the image filter}
\lineiii{filter_opts}{List}{Options of the filter}
\hline
\lineiii{scale}{String}{"lin"=linear scaling "log"=logarithmic scaling}
\lineiii{cd}{Float}{Logarithmic scaling parameter (use for logarithmic scaling)}
\lineiii{mn}{Float}{Minimum value of the map (use for the scaling)}
\lineiii{mx}{Float}{Maximum value of the map (use for the scaling)}
\hline
\lineiii{l_n}{Int}{Number of contour levels}
\lineiii{l_min}{Float}{Minimum value of contours}
\lineiii{l_max}{Float}{Maximum value of contours}
\lineiii{l_kx}{Int}{Contour precision in x}
\lineiii{l_ky}{Int}{Contour precision in y}
\lineiii{l_color}{Int}{Contour color (0-255)}
\lineiii{l_cruch}{String}{Remove background map when plotting contours ("yes" or "no")}
\hline
\lineiii{b_weight}{Int}{Box line width (0 or 1)}
\lineiii{b_xopts}{Tuple}{Ticks box parameters in x}
\lineiii{b_yopts}{Tuple}{Ticks box parameters in y}
\lineiii{b_color}{Int}{Box color (0-255)}
\hline									    
\end{tableiii}	

All these parameters may be displayed or set using the methods~:
\begin{verbatim}
>>> nb.parameters.get('mode')
>>> nb.parameters.set('mode','T')
\end{verbatim}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{How to define the observer position ?}

When creating an image from a model, one has to choose the observer position, the look at point and
the orientation of the head. 
The user has tree possibilities to define these parameters~:

\begin{enumerate}

\item Define manually the observer matrix \var{obs}.\var{obs} is a $4\times3$ array matrix.
Meaning of the four vectors composing this matrix is given in the following table~:

\begin{tableii}{l|l}{}{\var{obs}}{Meaning}
\lineii{obs[0]}{position of the observer}
\lineii{obs[1]}{position of the look at point (with respect to the position of the observer)}
\lineii{obs[2]}{position of the head (with respect to the position of the observer)}
\lineii{obs[3]}{position of the arm (with respect to the position of the observer)}
\hline									    
\end{tableii}	


\item Using the parameters \var{xp}, \var{x0} and \var{alpha},
where \var{x0} is the observer position, \var{xp} is the look at point
and \var{alpha} the angle between the head and the $z$ axis.


\item Using the parameters \var{view} and \var{r_obs}.
\var{view} can be equal to 'xy', 'xz' or 'yz', the projection being parallel to
one of the main axis. \var{r_obs} gives the distance between the observer and the 
look at point.

\end{enumerate}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Stereo mode}

When creating stereo view, you can specify the eye you are looking with ('right','left').
When exposition the model with the method \texttt{\textbf{expose}}, the observer will be rotate
around an axis parallel to its head, with a center rotation in the direction of the look at point,
at a distance \var{foc} of the eye. The angle of the rotation is such as to move the observer 
of a distance (\var{dist_eye})/2.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Perspective}

You have two possibilties for the perspective view. If \var{persp}='on', the model is projectec
using a frustrum projection matrix. In the other case, it uses an ortho matrix (orthogonal projection).
The near and far clipping planes are given by the parameter \var{clip}. The
left, right, bottom and top clipping planes are given by the parameter \var{size}.
If \var{cut} is set to 'yes', particles outside the box defined by the 6 planes are not displayed.



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Units parameters}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

The new version of \class{pNbody} also uses a default parameters used for units conversion.
The list and the meaning of these parameters is given in the following table~:

\begin{tableiii}{l|l|l}{}{\var{parameter}}{Type}{Meaning}
\lineiii{xi}{Float}{Hydrogen mass fraction}
\lineiii{ionisation}{Int}{Ionisation flag (ionized gas = 1, neutral gaz = 0)}
\lineiii{metalicity}{Int}{Metalicity index (between 0 and 5), used for cooling function}
\lineiii{coolingfile}{String}{Path to the file containing the tabulated cooling function}
\lineiii{Nsph}{Int}{Number of sph neighbors (unused)}
\lineiii{Cosmo}{String}{use cosmological units ('yes' or 'no')}
\lineiii{OmegaLambda}{Float}{Omega Lambda}
\lineiii{Omega0}{Float}{Omega matter}
\lineiii{UnitLength\_in\_cm}{Float}{Model units lenght in cm}
\lineiii{UnitMass\_in\_g}{Float}{Model units mass in g}
\lineiii{UnitVelocity\_in\_cm_per_s}{Float}{Model units velocity in cm/s}
\hline									    
\end{tableiii}	

All these parameters may be displayed or set using the methods~:
\begin{verbatim}
>>> nb.unitsparameters.get('HubbleParam')
>>> nb.unitsparameters.set('HubbleParam',0.73)
\end{verbatim}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Main module functions}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

These part describe all instances contained in an \class{pNbody} object.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Io functions}



%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{Nbody}{\optional{p_name=None},
                        \optional{pos=None},
			\optional{vel=None},
			\optional{mass=None},
			\optional{num=None},
			\optional{npart=None},
			\optional{ftype=None},
			\optional{status='old'},
			\optional{byteorder=sys.byteorder},
			\optional{pio='no'},
			\optional{log=None}}    
%--------------------------------------------------------------------------------------------------

This instance is the constructor for the \class{pNbody} object. Optional arguments are:

\begin{itemize}
\item \var{p_name}: 	name of the file or list of files containing the data (default=None)
\item \var{pos}: 	positions of particles ($n\times 3$ float32 Numeric array)(default=None)
\item \var{vel}: 	velocities of particles ($n\times 3$ float32 Numeric array)(default=None)
\item \var{mass}: 	mass of particles ($n$ Float Numeric array)(default=None)
\item \var{num}: 	identifier of particles ($n$ Int Numeric array)(default=None)
\item \var{npart}: 	Number of particles of each type (List) (default=None)
\item \var{ftype}:	type of the \var{p_file} (default=None)
    \begin{tableii}{l|l}{code}{Value}{Meaning}
    \lineii{"binary"}{standard format of the Geneva Observatory Nbody files}
    \lineii{"gadget"}{gadget file}
    \hline
    \end{tableii}
\item \var{status}: 	status of the file, \var{"new"} or \var{"old"} (default=\var{"old"})
\item \var{byteorder}:	byte order "littelendian" or "bigendian" (default=sys.byteorder)
\item \var{pio}:	parallel input/output (default="no")
\item \var{log}:	pointer to log ouput object (default=None)
\end{itemize}

If \var{status} = 'old', the constructor automatically call the function \bfcode{read} wich
will read the content of the file(s) in the \var{p_name}. 
If \var{status} = 'new', defaut values are given to the variables.
One the constructor has been called, all optional varables are are initialized.
The following variables are also initialized~:
\begin{itemize}
\item \var{nbody}: number of particles for the current node
\item \var{nbody_tot}: total number of particles
\item \var{npart_tot}: total number of particles of each type
\item \var{mass_tot}: total mass of the system
\end{itemize}

Other variables may be initialized, depending on the type of the file read.


\begin{verbatim}
>>> from pNbody import *
>>> nb = Nbody('disk.gad',ftype='gadget')
>>> nb.pos[0:10]
array([[  4.89041433e-02,   2.52863064e+01,  -7.45196819e+00],
       [  5.82345047e+01,  -5.67267685e+01,   1.64647083e+01],
       [  1.17894821e+01,  -5.01083970e-01,   3.68080497e+00],
       [ -2.43042755e+01,  -2.24240952e+01,   5.40977783e+01],
       [ -1.03210754e+01,   8.96411300e-01,  -5.02210388e+01],
       [ -1.38344803e+01,  -2.56113482e+00,  -1.29380960e+01],
       [  1.84468384e+01,  -3.16423264e+01,   2.17839069e+01],
       [  6.11360121e+00,   1.42906122e+01,   3.05427265e+01],
       [ -7.02638292e+00,   2.44790745e+01,   9.55757523e+00],
       [  8.33313751e+00,  -5.49589968e+00,  -4.00754318e+01]], type=float32)
>>> nb.mass_tot
2.3262434005737305
>>> nb.npart
array([   0, 2001, 1000,    0,    0,    0])
\end{verbatim}
\end{funcdesc}






%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Init functions}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{init}{}
%--------------------------------------------------------------------------------------------------
Initialize a model. Ensure that all variables are well defined.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{set_ftype}{\optional{ftype='binary'},\optional{npart=None}}
%--------------------------------------------------------------------------------------------------
Return a new object with a type defined by \var{ftype}.


\begin{verbatim}
>>> from pNbody import *
>>> nb = Nbody('disk.gad',ftype='gadget')
>>> nb.ftype
'Nbody_gadget'
>>> nb = nb.set_ftype('binary')
>>> nb.ftype
'Nbody_binary'
\end{verbatim}

\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{get_num}{}
%--------------------------------------------------------------------------------------------------
Compute the \var{num} variable in order to be consistent with  npart.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{get_spec_vars}{}
%--------------------------------------------------------------------------------------------------
Return specific variables default values for the class
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{set_pio}{pio}
%--------------------------------------------------------------------------------------------------
Set parallel input/output or not io.
\var{pio} may be "yes" or "no".
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{rename}{p_name}
%--------------------------------------------------------------------------------------------------
Rename the file(s). \var{p_name} may be a string or a list of
string, in case of multiple files.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{set_filenames}{p_name,\optional{pio=None}}
%--------------------------------------------------------------------------------------------------
Set the local and global names, in case of parallel input/output.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{print_filenames}{}
%--------------------------------------------------------------------------------------------------
Print files names
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{get_massarr_and_nzero}{}
%--------------------------------------------------------------------------------------------------
Return the \var{massarr} and \var{nzero} variables, computed
from \var{mass}.
\end{funcdesc}













%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Parameters functions}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{set_parameters}{params}
%--------------------------------------------------------------------------------------------------
Set parameters for the class.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{set_unitsparameters}{params}
%--------------------------------------------------------------------------------------------------
Set units parameters for the class.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{set_local_system_of_units}{}
%--------------------------------------------------------------------------------------------------
Set local system of units
\end{funcdesc}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Informations functions}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{info}{}
%--------------------------------------------------------------------------------------------------
Write informations about the object variables content.
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{spec_info}{}
%--------------------------------------------------------------------------------------------------
Write specific info.		
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{object_info}{}
%--------------------------------------------------------------------------------------------------
Write class(object) info. 	
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{nodes_info}{}
%--------------------------------------------------------------------------------------------------
Write info on nodes. 	
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{memory_info}{}
%--------------------------------------------------------------------------------------------------
Write info on memory size of the current object (only counting arrays size)
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{get_list_of_array}{}
%--------------------------------------------------------------------------------------------------
Return the list of numarray vectors of size nbody.		
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{get_list_of_method}{}
%--------------------------------------------------------------------------------------------------
Return the list of instance methods (functions).	
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{get_list_of_vars}{}
%--------------------------------------------------------------------------------------------------
Get the list of vars that are linked to the model.	
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{has_array}{name}
%--------------------------------------------------------------------------------------------------
Return true if the object \class{pNbody} has an array called \texttt{self.name}
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{find_vars}{name}
%--------------------------------------------------------------------------------------------------
This function return a list of variables defined in the current object.
\end{funcdesc}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Read and write functions}



%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{read}{}
%--------------------------------------------------------------------------------------------------
Read the file(s) defined by \var{p_name}.
If the values of the files is \var{None}, they are simply ignored.
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{open_and_read}{name,readfct}
%--------------------------------------------------------------------------------------------------
Open and read the file \var{name}, using the
reading function \var{readfct}.
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{write}{}
%--------------------------------------------------------------------------------------------------
Write the file(s) defined by \var{p_name}.
If the values of the files is \var{None}, they are simply not written. 
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{open_and_write}{name,writefct}
%--------------------------------------------------------------------------------------------------
Open and write the file \var{name}, using the
wrinting function \var{readfct}.
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{write_num}{name}
%--------------------------------------------------------------------------------------------------
Write the content of the \var{num} in a file \var{name}.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{read_num}{name}
%--------------------------------------------------------------------------------------------------
Not implemented yes.
\end{funcdesc}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Physical values and operations}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{rxyz}{}
%--------------------------------------------------------------------------------------------------
Return a 1xn Float array that corresponds to
the distance from the center of each particle.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{phi_xyz}{}
%--------------------------------------------------------------------------------------------------
Return a 1xn Float array that corresponds to
the azimuth in spherical coordinate of each particle.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{theta_xyz}{}
%--------------------------------------------------------------------------------------------------
Return a 1xn Float array that corresponds to
the elevation angle in spherical coordinate of each particle.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{rxy}{}
%--------------------------------------------------------------------------------------------------
Return a 1xn Float array that corresponds to
the projected distance from the center of each particle.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{cart2sph}{}
%--------------------------------------------------------------------------------------------------
Transform carthesian coodinates x,y,z into spherical
coordinates r,p,t 
Return a 3xn Float array.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{cart2sph}{\optional{pos=None}}
%--------------------------------------------------------------------------------------------------
Transform carthesian coodinates x,y,z into spherical
coordinates r,p,t 
Return a 3xn Float array.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{sph2cart}{\optional{pos=None}}
%--------------------------------------------------------------------------------------------------
Transform spherical coordinates r,p,t into carthesian
coodinates x,y,z
Return a 3xn Float array.
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{vrxyz}{}
%--------------------------------------------------------------------------------------------------
Return a 1xn Float array that corresponds to
the radial velocity in spherical system
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{Vr}{}
%--------------------------------------------------------------------------------------------------
Return the radial velocies of particles
The output is an 3xn Float array.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{Vt}{}
%--------------------------------------------------------------------------------------------------
Return the tangential velocies of particles
The output is an 3xn Float array.
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{get_nt}{}
%--------------------------------------------------------------------------------------------------
Return the total number of particles.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{get_ns}{}
%--------------------------------------------------------------------------------------------------
Return in an array the number of particles of each node.
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{get_mass_tot}{}
%--------------------------------------------------------------------------------------------------
Return the total mass of system.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{get_npart_tot}{}
%--------------------------------------------------------------------------------------------------
Return the total nuber of particles of each types.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{cm}{}
%--------------------------------------------------------------------------------------------------
Return the mass center of the model. 
The output is an $3\times 1$ Float Numeric array.
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{get_histocenter}{\optional{rbox=50},\optional{nb=500}}
%--------------------------------------------------------------------------------------------------
Return the position of the higher density region found by the function 
\bfcode{\textbf{histocenter}}.
\begin{itemize}
\item \var{rbox}: box dimension, where to compute the histograms (default=\var{50})
\item \var{nb}: number of bins for the histograms (default=\var{500})
\end{itemize}
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{cv}{}
%--------------------------------------------------------------------------------------------------
Return the barycenter of the velocities of the model. 
The output is an $3\times 1$ Float Numeric array.
\end{funcdesc}



%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{minert}{}
%--------------------------------------------------------------------------------------------------
Return the diagonal of the inertial momentum $I$. Each component of the diagonal is
defined as:
\begin{equation}
I_j=\sqrt{ \frac{1}{M}\,\sum m_i \cdot x_j^2 },
\end{equation}
where $j=x,y,z$ and $M$ is the total mass. $i$ runs over all particles.
The output is an $3\times 1$ Float Numeric array.
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{x_sigma}{}
%--------------------------------------------------------------------------------------------------
Return the norm of the position dispersions.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{v_sigma}{}
%--------------------------------------------------------------------------------------------------
Return the norm of the velocity dispersions $\sigma$ :
\begin{equation}
\sigma=\sqrt{ \frac{1}{M}\,\sum m_i \cdot \left( (vx_i-vcx)^2+(vy_i-vcy)^2+(vz_i-vcz)^2 \right) },
\end{equation}
where $[vcx,vcy,vcz]$ is the barycenter of velocities. $i$ runs over all particles.
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{dx_mean}{}
%--------------------------------------------------------------------------------------------------
Return the average distance between particles.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{dv_mean}{}
%--------------------------------------------------------------------------------------------------
Return the average relative speed between particles.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{Ekin}{}
%--------------------------------------------------------------------------------------------------
Return the total kinetic energy.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{ekin}{}
%--------------------------------------------------------------------------------------------------
Return the total specific kinetic energy.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{Epot}{eps}
%--------------------------------------------------------------------------------------------------
Return the total potential energy using the softening lenght \var{eps} 
(may take a very long time to compute).
WARNING : THIS FUNCTION DO NOT WORK IN MPI MODE
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{epot}{eps}
%--------------------------------------------------------------------------------------------------
Return the total specific potential energy using the softening lenght \var{eps} 
(may take a very long time to compute)
WARNING : THIS FUNCTION DO NOT WORK IN MPI MODE
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{L}{}
%--------------------------------------------------------------------------------------------------
Return the angular momentum in x,y,z of all particles.
The output is an 3xn Float array. 
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{l}{}
%--------------------------------------------------------------------------------------------------
Return the specific angular momentum in x,y,z of all particles.
The output is an 3xn Float array. 
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{Ltot}{}
%--------------------------------------------------------------------------------------------------
Return the total angular momentum.
The output is an $3\times 1$ Float Numeric array. 
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{ltot}{}
%--------------------------------------------------------------------------------------------------
Return the specific total angular momentum.
The output is an $3\times 1$ Float Numeric array. 
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{Pot}{x,eps}
%--------------------------------------------------------------------------------------------------
Return the potential at a given position, using the softening lenght \var{eps}. 
\var{x} is a $3\times 1$ Float Numeric array.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{tork}{acc}
%--------------------------------------------------------------------------------------------------
Return the total tork on the system due to the force
acting on each particle (acc).
The output is an 3xn Float array.
\var{acc} is an 3xn Float array. 
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{dens}{\optional{r=None},\optional{nb=25},\optional{rm=50}}
%--------------------------------------------------------------------------------------------------
Return the number density at radius \var{r} (supposing a spherical density distribution).
If \var{r} is not specified, it is computed with \var{nb} and \var{rm}.
The output is an n x 1 Float array. 
This function do not use \var{mass}.
\begin{itemize}
\item \var{r}: 	radius where to compute the surface density ($n\times 1$ Numeric array) (default=\var{None})
\item \var{nb}: 	number of bins (default=\var{25})
\item \var{rm}: 	maximal radius (default=\var{50})
\end{itemize}
The output is an $n\times 1$ Float Numeric array. 
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{mdens}{\optional{r=None},\optional{nb=25},\optional{rm=50}}
%--------------------------------------------------------------------------------------------------
Return the surface density at radius \var{r} (supposing a spherical density distribution).
If \var{r} is not specified, it is computed with \var{nb} and \var{rm}.
\begin{itemize}
\item \var{r}: 	radius where to compute the surface density ($n\times 1$ Numeric array) (default=\var{None})
\item \var{nb}: 	number of bins (default=\var{25})
\item \var{rm}: 	maximal radius (default=\var{50})
\end{itemize}
The output is an $n\times 1$ Float Numeric array. 
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{mr}{\optional{r=None},\optional{nb=25},\optional{rm=50}}
%--------------------------------------------------------------------------------------------------
Return tthe mass inside radius \var{r} (supposing a spherical density distribution).
If \var{r} is not specified, it is computed with \var{nb} and \var{rm}.
\begin{itemize}
\item \var{r}: 	radius where to compute the surface density ($n\times 1$ Numeric array) (default=\var{None})
\item \var{nb}: 	number of bins (default=\var{25})
\item \var{rm}: 	maximal radius (default=\var{50})
\end{itemize}
The output is an $n\times 1$ Float Numeric array. 
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{sdens}{\optional{r=None},\optional{nb=25},\optional{rm=50}}
%--------------------------------------------------------------------------------------------------
Return the number surface density at radius \var{r}.
If \var{r} is not specified, it is computed with \var{nb} and \var{rm}.
This function do not use \var{mass}.
\begin{itemize}
\item \var{r}: 	radius where to compute the surface density ($n\times 1$ Numeric array) (default=\var{None})
\item \var{nb}: 	number of bins (default=\var{25})
\item \var{rm}: 	maximal radius (default=\var{50})
\end{itemize}
The output is an $n\times 1$ Float Numeric array. 
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{msdens}{\optional{r=None},\optional{nb=25},\optional{rm=50}}
%--------------------------------------------------------------------------------------------------
Return the mass surface density at radius \var{r}.
If \var{r} is not specified, it is computed with \var{nb} and \var{rm}.
\begin{itemize}
\item \var{r}: 	radius where to compute the surface density ($n\times 1$ Numeric array) (default=\var{None})
\item \var{nb}: 	number of bins (default=\var{25})
\item \var{rm}: 	maximal radius (default=\var{50})
\end{itemize}
The output is an $n\times 1$ Float Numeric array. 
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{zprof}{\optional{z=None},\optional{r=2.5},\optional{dr=0.5},\optional{nb=25},\optional{zm=5}}
%--------------------------------------------------------------------------------------------------
Return the $z$-profile in an $n\times 1$ Float Numeric array, for a given radius \var{r}.
\begin{itemize}
\item \var{z}: 	bins in z, $n\times 1$ Numeric array (default=\var{None})
\item \var{r}: 	radius of the cut (default=\var{2.5})
\item \var{dr}: 	width in r of the cut (default=\var{0.5})
\item \var{nb}: 	number of bins (default=\var{25})
\item \var{zm}: 	maximal height (default=\var{5})
\end{itemize}

\begin{center}
\textbf{!!! This routine works only if particles have equal masses !!!}
\end{center}
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{sigma}{\optional{r=None},\optional{nb=25},\optional{rm=50}}
%--------------------------------------------------------------------------------------------------
Return the 3 velocity dispersions (in cylindrical coordinates) and the mean azimuthal velocity curve.
If \var{r} is not specified, it is computed with \var{nb} and \var{rm}.
\begin{itemize}
\item \var{r}: 	radius where to compute the values ($n\times 1$ Numeric array) (default=\var{None})
\item \var{nb}: 	number of bins (default=\var{25})
\item \var{rm}: 	maximal radius (default=\var{50})
\end{itemize}

The output is a list (\var{r,sr,st,sz,mt}) of 5 $n\times 1$ Float Numeric arrays,
where \var{r} is the radius, \var{sr} the radial velocity dispersion, \var{st}, the azimuthal velocity dispersion,
\var{sz}, the vertical velocity dispersion and \var{mt}, the mean azimuthal velocity curve.
\begin{center}
\textbf{!!! This routine works only if particles have equal masses !!!}
\end{center}
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{histovel}{\optional{nb},\optional{vmin},\optional{vmax},\optional{plot},\optional{mode}}
%--------------------------------------------------------------------------------------------------
Return and plot the histogram of the norm of velocities or of the radial velocities.
\begin{itemize}
\item \var{nb}: 	        number of bins (default=\var{100})
\item \var{vmin}: 	maximum velocity (default=\var{None})
\item \var{vmax}: 	minimum velocity (default=\var{None})
\item \var{plot}: 	'yes'=trace a plot, 'no'=don't trace a plot (default=\var{'no'})
\item \var{mode}: 	'n'=norm of the velocities, 'r'=radial velocities (default=\var{'n'})
\end{itemize}
The output is a list (\var{r,h}) of 2 $n\times 1$ Float Numeric arrays,
where \var{r} is the radius and \var{h} the values of the histogram.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{zmodes}{\optional{nr=32},\optional{nm=16},\optional{rm=32}}
%--------------------------------------------------------------------------------------------------
Compute the vertical modes of a model
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{zmodes}{\optional{nr=32},\optional{nm=16},\optional{rm=32}}
%--------------------------------------------------------------------------------------------------
Compute the density modes of a model
\end{funcdesc}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Thermodynamic functions}

These functions works if \var{rho} (density of particles) and \var{u} (specific energy of particles) 
are correctely defined.

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{Rho}{}
%--------------------------------------------------------------------------------------------------
Return the gas density of the model.
The output is an nx1 Float array.
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{T}{}
%--------------------------------------------------------------------------------------------------
Return the gas temperature of the model.
The output is an nx1 Float array.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{A}{}
%--------------------------------------------------------------------------------------------------
Return the gas entropy of the mode
The output is an nx1 Float array.
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{P}{}
%--------------------------------------------------------------------------------------------------
Return the gas pressure of the model.
The output is an nx1 Float array.
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{Tcool}{}
%--------------------------------------------------------------------------------------------------
Return the cooling time of the model.
The output is an nx1 Float array.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{Ne}{}
%--------------------------------------------------------------------------------------------------
Return the electron density of the model. 
The output is an nx1 Float array.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{S}{}
%--------------------------------------------------------------------------------------------------
Return the `entropy` of the model, defined as
S = T * Ne**(1-gamma)
The output is an nx1 Float array.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{Lum}{}
%--------------------------------------------------------------------------------------------------
Return the luminosty of the model, defined as
Lum = m*u/Tcool = m*Lambda/rho
The output is an nx1 Float array.
\end{funcdesc}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Adding particles}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{append}{new}
%--------------------------------------------------------------------------------------------------
Append to the current \class{Nbody} object, particles form the 
\class{Nbody} object \var{new}.
\end{funcdesc}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Selection of particles}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{selectc}{c}
%--------------------------------------------------------------------------------------------------
Return an \class{Nbody} object that contains only particles where the 
corresponding value in \var{c} is not zero.
\var{c} is a $n\times 1$ Numeric array.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{selectp}{\optional{lst},\optional{file}}
%--------------------------------------------------------------------------------------------------
Return an \class{Nbody} object that contains only particles with indexes.
 
The list of indexes is given either by \var{lst} ($n\times 1$ Int Numeric array) or	 
by the name (\var{file}) of a file containing the list of id's. 	     	 
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{sub}{\optional{n1},\optional{n2}}
%--------------------------------------------------------------------------------------------------
Return an \class{Nbody} object that have particles with indexes in the range [\var{n1},\var{n2}].
\begin{itemize}
\item \var{n1}: number of the first particle (default=\var{1})
\item \var{n2}: number of the last particle (default=\var{None})
\end{itemize}
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{reduc}{n}
%--------------------------------------------------------------------------------------------------
Return an \class{Nbody} object that contains a fraction 1/\var{n} of particles.
Only particles that have an index equal to a multiple of \var{n} are conserved.
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{select}{type}
%--------------------------------------------------------------------------------------------------
Return an \class{Nbody} object that contain only particles of type \var{type}.
This function depends on the object format.
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{getindex}{num}
%--------------------------------------------------------------------------------------------------
Return an array of index of a particle from its specific number id.
The array is empty if no particle corresponds to the specific number id. 
num : Id of the particle
\end{funcdesc}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Redistribution of particles}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{redistribute}{}
%--------------------------------------------------------------------------------------------------
This function redistribute particles amoung all nodes in order to
have a similar number of particles per nodes
\end{funcdesc}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Geometrical operations}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{cmcenter}{}
%--------------------------------------------------------------------------------------------------
Move the \class{Nbody} object in order to center the mass center at the origin.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{cvcenter}{}
%--------------------------------------------------------------------------------------------------
Center the center of velocities at the origin.
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{histocenter}{\optional{rbox},\optional{nb}}
%--------------------------------------------------------------------------------------------------
Move the \class{Nbody} object in order to center the higher
density region found near the mass center.
The higher density region is determined with density histograms.
\begin{itemize}
\item \var{rbox}: box dimension, where to compute the histograms (default=\var{50})
\item \var{nb}: number of bins for the histograms (default=\var{500})
\end{itemize}
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{hdcenter}{}
%--------------------------------------------------------------------------------------------------
Move the \class{Nbody} object in order to center the higher
density region found.
The higher density region is the maximum of variable \var{rho}.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{translate}{dx,\optional{mode}}
%--------------------------------------------------------------------------------------------------
Translate the positions or the velocities of the object.
\begin{itemize}
\item \var{dx}: translation vector ($3\times 1$ Float0 Numeric array)
\item \var{mode}: 'p'= translate the positions, 'v'= translate the velocities (default=\var{'p'})
\end{itemize}
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{rotate}{\optional{angle},\optional{mode},\optional{axis}}
%--------------------------------------------------------------------------------------------------
Rotate the positions and/or the velocities of the object around a specific axis.
\begin{itemize}
\item \var{angle}: rotation angle in radian (default=\var{0})
\item \var{mode}: 'p'= rotate only the positions, 'v'=rotate only the velocities, 'a'=rotate the positions and velocities (default=\var{'a'})
\item \var{axis}: axis of rotation : 'x', 'y', 'z' or $[x,y,z]$ (default=\var{'x'})
\end{itemize}
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{rotate2}{\optional{angle},\optional{axis},\optional{point}}
%--------------------------------------------------------------------------------------------------
Rotate the positions and/or the velocities of the object around a specific axis.
This function rotate positions and velocities
\begin{itemize}
\item \var{angle}: rotation angle in radian (default=\var{0})
\item \var{axis}: rotation axis
\item \var{point}: rotation center
\end{itemize}
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{align}{axis,\optional{mode},\optional{sgn},\optional{fact}}
%--------------------------------------------------------------------------------------------------
Rotate the object in order to align the axis \var{axis} with the $z$ axis. 
\begin{itemize}
\item \var{axis}: axis to align : $[x,y,z]$ 
\item \var{mode}: 'p'= rotate only the positions, 'v'=rotate only the velocities, 'a'=rotate the positions and velocities (default=\var{'a'})
\item \var{sgn}: '+': normal rotation, '-': reverse sense of rotation (default='+')
\item \var{fact}: multiply the rotation angle by a factor \var{fact} (default=\var{None})
\end{itemize}
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{align2}{\optional{axis1=[1,0,0]},\optional{axis2=[0,0,1]},point=[0,0,0]}
%--------------------------------------------------------------------------------------------------
Rotate the object in order to align the axis1 \var{axis1} with the axis2 \var{axis2}.
\begin{itemize}
\item \var{axis1}: first axis
\item \var{axis2}: second axis
\item \var{point}: center of rotation
\end{itemize}
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{spin}{\optional{omega=None},\optional{L=None},\optional{j=None},\optional{E=None}}
%--------------------------------------------------------------------------------------------------
Spin the object with angular velocity "omega" (rigid rotation).
Omega is a 1 x 3 array object.
If L (total angular momentum) is explicitely given, compute Omega from L (1 x 3 array object).
\begin{itemize}
\item \var{omega}: first axis
\item \var{L}: desired angular momentum
\item \var{j}: desired energy fraction in rotation
\item \var{E}: Total energy (without rotation)
\end{itemize}
\end{funcdesc}




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Specific parallel functions}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{gather_pos}{}
%--------------------------------------------------------------------------------------------------
Gather in a unique array all positions of all nodes.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{gather_vel}{}
%--------------------------------------------------------------------------------------------------
Gather in a unique array all velocites of all nodes.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{gather_mass}{}
%--------------------------------------------------------------------------------------------------
Gather in a unique array all mass of all nodes.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{gather_num}{}
%--------------------------------------------------------------------------------------------------
Gather in a unique array all num of all nodes.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{gather_vec}{}
%--------------------------------------------------------------------------------------------------
Gather in a unique array all vectors vec of all nodes.
\end{funcdesc}




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Graphical functions}\label{graphfuncts}



%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{display}{parameters,\optional{palette=None},\optional{save=None}}
%--------------------------------------------------------------------------------------------------
Display the model using parameters \var{parameters}.
This function allows to display or save an image from an \class{Nbody} object. 
It calls the method \texttt{\textbf{Map}}, and display or save it.
\begin{itemize}
\item \var{parameters}: display parameters (see \ref{displayparameters})
\item \var{palette}: name of the palette (file in \texttt{rgb_tables/} directory)
\item \var{save}: output file name ('.gif' or '.fits')
\end{itemize}

\begin{verbatim}
>>> from pNbody import *
>>> nb = Nbody('gadget_z00.dat',ftype='gadget')
>>> nb.display()
>>> nb.display(size=(10000,10000),shape=(256,256),palette='lut2')
>>> params = {"size":(10000,10000),"shape":(256,256),"filter_name":'convol'}
>>> nb.display(params,palette='rainbow4')
\end{verbatim}

\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{show}{parameters}
%--------------------------------------------------------------------------------------------------
This function is an alias to the function \var{display}.


\begin{verbatim}
>>> from pNbody import *
>>> nb = Nbody('gadget_z00.dat',ftype='gadget')
>>> nb.show()
>>> nb.show(size=(10000,10000),shape=(256,256),palette='lut2')
>>> params = {"size":(10000,10000),"shape":(256,256),"filter_name":'convol'}
>>> nb.show(params,palette='rainbow4')
\end{verbatim}

\end{funcdesc}



%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{Map}{parameters}
%--------------------------------------------------------------------------------------------------
This function creates a map using parameters defined in \var{parameters}, where
\var{parameters} corresponds to parameters defined in section \ref{displayparameters}.

It calls the methods
\texttt{\textbf{CombiMap}} that create the matrix \var{mat}.

Then, it makes an integer matrix (\var{matint}) calling the function 
\texttt{\textbf{set\_ranges}}
and optionally add contours or box, using the functions
\texttt{\textbf{contours}}
and \texttt{\textbf{add_box}}.

It finally returns a tuple (\var{mat},\var{matint},\var{mn\_opts},\var{mx\_opts},\var{cd\_opts})

\begin{itemize}
\item \var{mat}: real matrix (Nx*Ny Float array)
\item \var{matint}: image matrix with values between 0 and 255 (Nx*Ny Int array)
\item \var{mn\_opt}: minimum physical value used to create \var{matint}
\item \var{mx\_opt}: maximum physical value used to create \var{matint}
\item \var{cd\_opt}: \var{cd} parameter used to create \var{matint}
\end{itemize}
%
\begin{verbatim}
>>> from pNbody import *
>>> nb = Nbody('gadget_z00.dat',ftype='gadget')
>>> mat,matint,mn_opt,mx_opt,cd_opt = nb.Map()
>>> mplot(matint)
\end{verbatim}


\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{CombiMap}{parameters}
%--------------------------------------------------------------------------------------------------

This function returns a Float numarray matrix corresponding to the physical value defined
by the parameter \texttt{mode}.
The function uses either  \texttt{\textbf{ComputeMeanMap}}, \texttt{\textbf{ComputeSigmaMap}},
or use directely the function \texttt{\textbf{ComputeMap}} to compute the desired matrix.
The meaning of the parameter \texttt{mode} is given in the following table.

    \begin{tableiii}{l|l|l}{}{Value}{Meaning}{Formula}
    \lineiii{"sr"}{dispertion in r}{$\sqrt{\langle\sum m\, r^2\rangle/\langle\sum m\rangle-(\langle\sum m\, r\rangle/\langle\sum m\rangle)^2}$}
    \lineiii{"svr"}{dispertion in vr}{$\sqrt{\langle\sum m\, vr^2\rangle/\langle\sum m\rangle-(\langle\sum m\, vr\rangle/\langle\sum m\rangle)^2}$}
    \lineiii{"svxyr"}{dispertion in vxy}{$\sqrt{\langle\sum m\, vxy^2\rangle/\langle\sum m\rangle-(\langle\sum m\, vxy\rangle/\langle\sum m\rangle)^2}$}
    \lineiii{"svtr"}{dispertion in vt}{$\sqrt{\langle\sum m\, vt^2\rangle/\langle\sum m\rangle-(\langle\sum m\, vt\rangle/\langle\sum m\rangle)^2}$}
    \lineiii{"szr"}{ratio sigma z/sigma r}{}
    \hline
    \end{tableiii}

If the value of \texttt{mode} may also be set to a variable or function name. In this case,
a map using the function \texttt{\textbf{ComputeMeanMap}}, with a physical value taken as the given
variable is returned.
%
\begin{verbatim}
>>> from pNbody import *
>>> nb = Nbody('gadget_z00.dat',ftype='gadget')
>>> nb = nb.select('gas')
>>> mat = nb.CombiMap(mode='T',filter_name='convol')
>>> matint,mn_opt,mx_opt,cd_opt = set_ranges(mat,scale='log',cd=0,mn=0,mx=0)
>>> mplot(matint,palette='rainbow4')
>>> mat = nb.CombiMap(mode='log10(nb.T())',filter_name='convol')
>>> matint,mn_opt,mx_opt,cd_opt = set_ranges(mat,scale='lin',cd=0,mn=7,mx=12)
>>> mplot(matint,palette='rainbow4')
\end{verbatim}

\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{ComputeMeanMap}{parameters,mode1}
%--------------------------------------------------------------------------------------------------
Compute the mean map of an observable and return int in an float32 numarray matrix.

	\begin{equation}
	M = \frac{M_1}{M_0}
	\end{equation}
	
$M_0$ is the zero momentum map and $M_1$ is the first momentum map of the variable given by \texttt{mode1}.
%
\begin{verbatim}
>>> from pNbody import *
>>> nb = Nbody('disk.dat',ftype='gadget')
>>> nb = nb.select('disk')
>>> mat = nb.ComputeMeanMap(filter_name='convol',size=(75,75),view='xy',mode1='z')
>>> matint,mn_opt,mx_opt,cd_opt = set_ranges(mat,scale='lin',cd=0,mn=-10,mx=10)
>>> mplot(matint,palette='rainbow4')
\end{verbatim}

\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{ComputeSigmaMap}{parameters,mode1,mode2}
%--------------------------------------------------------------------------------------------------
Compute the dispersion map an observable and return it in an float32 numarray matrix.

	\begin{equation}
	M = \sqrt{ \frac{M_2}{M_0} - \left(  \frac{M_1}{M_0} \right)^2  }
	\end{equation}

$M_0$ is the zero momentum map and $M_1$($M_2$) is a first(second) momentum map of the variable given by 
\texttt{mode1}(\texttt{mode2}).
%
\begin{verbatim}
>>> from pNbody import *
>>> nb = Nbody('disk.dat',ftype='gadget')
>>> nb = nb.select('disk')
>>> mat = nb.ComputeSigmaMap(filter_name='convol',size=(75,75),view='xy',mode1='z',mode2='z2')
>>> matint,mn_opt,mx_opt,cd_opt = set_ranges(mat,scale='lin',cd=0,mn=-2,mx=2)
>>> mplot(matint,palette='rainbow4')
\end{verbatim}

\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{ComputeMap}{parameters}
%--------------------------------------------------------------------------------------------------

Compute the momentum map of an observable and return it in an float32 numarray matrix.
It calls the functions~:

\begin{enumerate}

\item \texttt{\textbf{getval}} : 
If the physical value to plot is not dependent on the observer position, get it from
\var{mode}.

\item \texttt{\textbf{get_obs}} : 
if the observer position matrix \var{obs} is not defined, compute it using 
\var{x0}, \var{xp}, \var{alpha}, \var{view}, \var{r_obs}.

\item \texttt{\textbf{expose}} : 
expose the model, using
\var{obs}, \var{eye}, \var{dist_eye}, \var{foc}, \var{space}.

\item \texttt{\textbf{getval}} : 
If the physical value to plot depends on the observer position, get it now from
\var{mode}.

\item \texttt{\textbf{frustrum}} or \texttt{\textbf{ortho}} : Project the model, using
\var{clip} and \var{size}.

\item \texttt{\textbf{getval}} : 
If the physical value to plot depends on the observer position, get it now from
\var{mode}.

\item None : 
Performe some selections

\item \texttt{\textbf{viewport}} : perform viewport transformation using
\var{shape}.

\item \texttt{\textbf{mkmapsph}} or \texttt{\textbf{mkmap}} : compute the map using
\var{shape}.

\item \texttt{\textbf{apply_filter}} : apply filter on the map using
\var{filter_name} and \var{filter_opts}.

\end{enumerate}


The following table lists corresponding physical values fo the parameter \var{mode} 
that do not dependends on the observer position~:

    \begin{tableiii}{l|l|l}{}{Value}{Meaning}{Formula}
    \lineiii{"0"}{zero momentum}{$\sum m$}
    \lineiii{"m"}{zero momentum}{$\sum m$}
    \lineiii{"x"}{first momentum in x}{}
    \lineiii{"y"}{first momentum in y}{}
    \lineiii{"z"}{first momentum in z}{}
    \lineiii{"x2"}{second momentum in x }{}
    \lineiii{"y2"}{second momentum in y }{}
    \lineiii{"z2"}{second momentum in z }{}
    \lineiii{"vx"}{first velocity momentum in x}{$\sum m\, vx$}
    \lineiii{"vy"}{first velocity momentum in y}{$\sum m\, vy$}
    \lineiii{"vz"}{first velocity momentum in z}{$\sum m\, vz$}
    \lineiii{"vx2"}{second velocity momentum in x}{$\sum m\, vx^2$}
    \lineiii{"vy2"}{second velocity momentum in y}{$\sum m\, vy^2$}
    \lineiii{"vz2"}{second velocity momentum in z}{$\sum m\, vz^2$}
    \lineiii{"lx"}{first specific kinetic momemtum in x}{}
    \lineiii{"ly"}{first specific kinetic momemtum in y}{}
    \lineiii{"lz"}{first specific kinetic momemtum in z}{}   
    \lineiii{"Lx"}{first kinetic momemtum in x}{}
    \lineiii{"Ly"}{first kinetic momemtum in y}{}
    \lineiii{"Lz"}{first kinetic momemtum in z}{}	  
    \hline
%    \end{tableiii}    
%    \begin{tableiii}{l|l|l}{}{Value}{Meaning}{Formula}
    \lineiii{"u"}{first momentum of specific energy}{}
    \lineiii{"rho"}{first momentum of density }{}
    \lineiii{"T"}{first momentum of temperature}{}
    \lineiii{"A"}{first momentum of entropy}{}
    \lineiii{"P"}{first momentum of pressure}{}
    \lineiii{"Tcool"}{first momentum of cooling time}{}
    \lineiii{"Lum"}{first momentum of luminosity}{}
    \lineiii{"Ne"}{first momentum of electronic density}{}
    \hline
    \end{tableiii}            


The following table lists corresponding physical values fo the parameter \var{mode} 
that do dependends on the observer position~:
    
    \begin{tableiii}{l|l|l}{}{Value}{Meaning}{Formula}
    \lineiii{"r"}{first momentum of radial distance}{}
    \lineiii{"r2"}{second momentum of radial distance}{}
    \lineiii{"vr"}{first momentum of radial velocity}{}
    \lineiii{"vr2"}{second momemtum of radial velocity}{}    
    \lineiii{"vxyr"}{first momentum of radial velocity in the plane}{$\sum m\, (x\,vx + y\,vy)/\sqrt{x^2+y^2}$}
    \lineiii{"vxyr2"}{second momentum of radial velocity in the plane}{$\sum m\, [(x\,vx + y\,vy)/\sqrt{x^2+y^2}]^2$}
    \lineiii{"vtr"}{first momentum of tangential velocity in the plane}{$\sum m\, (x\,vx - y\,vy)/\sqrt{x^2+y^2}$}
    \lineiii{"vtr2"}{second momentum of tangential velocity in the plane}{$\sum m\, [(x\,vx - y\,vy)/\sqrt{x^2+y^2}]^2$}
    \hline
    \end{tableiii}


\begin{verbatim}
>>> from pNbody import *
>>> nb = Nbody('disk.dat',ftype='gadget')
>>> nb = nb.select('disk')
>>> nb.cmcenter()
>>> nb.rotate(axis='x',angle=pi/4)
>>> mat = nb.ComputeMap(filter_name='convol',size=(50,50),mode='vr')
>>> matint,mn_opt,mx_opt,cd_opt = set_ranges(mat,scale='lin',cd=0,mn=0,mx=0)
>>> mplot(matint,palette='rainbow4')
>>> mat = nb.ComputeMap(filter_name='convol',size=(50,50),mode='nb.rxyz()')
>>> matint,mn_opt,mx_opt,cd_opt = set_ranges(mat,scale='lin',cd=0,mn=0,mx=0.0004)
>>> mplot(matint,palette='rainbow4')
>>> mat = nb.ComputeMeanMap(filter_name='convol',size=(50,50),mode1='nb.rxyz()')
>>> matint,mn_opt,mx_opt,cd_opt = set_ranges(mat,scale='lin',cd=0,mn=0,mx=50)
>>> mplot(matint,palette='rainbow4')
\end{verbatim}




\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{expose}{obs,\optional{eye=None},\optional{dist_eye=None},\optional{foc=None},\optional{space='pos'}}
%--------------------------------------------------------------------------------------------------
Rotate and translate the object in order to be seen as if the 
observer was in \var{x0}, looking at a point in \var{xp}.
\begin{itemize}
\item \var{obs}: observer matrix
\item \var{eye}: 'right' or 'left'
\item \var{dist_eye}: distance between eyes (separation = angle)
\item \var{space}: "pos" or "vel"
\item \var{foc}: focal
\end{itemize}
\end{funcdesc}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{libutil module}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


These functions are not methods of the \class{Nbody} object. However, there are useful to
process some outputs of \class{Nbody} methods.


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{cross_product}{x,y}
%--------------------------------------------------------------------------------------------------

Return the cross product of two $3\times n$ arrays.

\end{funcdesc}



%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{histogram}{a,bins}
%--------------------------------------------------------------------------------------------------

Return the histogram ($n\times 1$ Float0 Numeric array) of the $n\times 1$ Float0 Numeric array \var{a}.
\var{bins} ($m\times 1$ Float0 Numeric array) specify the bins of the histogram.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{getr}{\optional{nr},\optional{nt},\optional{rm}}
%--------------------------------------------------------------------------------------------------

Return a sequence of number ($n\times 1$ Float0 Numeric array), where $n=\rm{nr}+1$  defined by:
\begin{equation}
        R_j = \rm{rm}\frac{exp\left[ j          /\left( \frac{1}{2}+\frac{\rm{nt}}{2\pi}  \right) \right]-1}
	                  {exp\left[ (\rm{nr}-1)/\left( \frac{1}{2}+\frac{\rm{nt}}{2\pi}  \right) \right]-1}
\end{equation}
\begin{verbatim}
>>> from Nbody import *
>>> getr()
array([  0.00000000e+00,   7.69677545e-02,  
	      1.69004032e-01,   2.79058904e-01,
	      4.10659999e-01,   5.68025574e-01,  
	      7.56199722e-01,   9.81214059e-01,
	      1.25028105e+00,   1.57202519e+00,  
	      1.95675946e+00,   2.41681589e+00,
	      2.96694083e+00,   3.62476762e+00,  
	      4.41138184e+00,   5.35199710e+00,
	      6.47676327e+00,   7.82173290e+00,  
	      9.43001676e+00,   1.13531658e+01,
	      1.36528233e+01,   1.64027011e+01,  
	      1.96909419e+01,   2.36229450e+01,
	      2.83247442e+01,   3.39470479e+01,  
	      4.06700700e+01,   4.87093057e+01,
	      5.83224396e+01,   6.98176049e+01,  
	      8.35632603e+01,   1.00000000e+02])
\end{verbatim}
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{get_eyes}{x0,xp,alpha,dr}
%--------------------------------------------------------------------------------------------------
Return the position of two eyes (two $3\times 1$ Float0 Numeric array).
\begin{itemize}
\item \var{x0}: position of the observer 
\item \var{xp}: position where the observer look at 
\item \var{alpha}: rotation around the axis (x0,xp)
\item \var{dx}: distance between eyes
\end{itemize}
\begin{verbatim}
>>> from pNbody import *
>>> get_eyes([0,-50,50],[0,0,0],0,5)
(array([  5., -50.,  50.], type=float32), array([ -5., -50.,  50.], type=float32))
\end{verbatim}
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{apply_filter}{mat,\optional{filter_name},\optional{filter_opts}}
%--------------------------------------------------------------------------------------------------

Apply a filter on an $n\times 1$ Float0 Numeric array.
The only supported filter has \var{filter_name}=\var{'convol'} and
\var{filter_opts}=\var{(nx,ny,sx,sy)}. The filter operates a convolution of
the array with a Gaussian kernel of half width \var{sx} and \var{sy} truncated
on radius \var{nx} and \var{ny}.

\begin{itemize}
\item \var{mat}: input array ($n\times m$ Float Numeric array)
\item \var{filter_name}: name of the filter  (default=\var{None})
\item \var{filter_opts}: parameters of the filter  (default=\var{None})      
\end{itemize}
\begin{verbatim}
>>> from pNbody import *
>>> from numarray import random_array as RandomArray
>>> mat = RandomArray.random([256,256])
>>> mplot(mat)
>>> mat = apply_filter(mat,name='convol',opt=[10,10,3,3])
>>> mplot(mat)
\end{verbatim}
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{set_ranges}{mat,\optional{scale},\optional{cd},\optional{mn},\optional{mx}}
%--------------------------------------------------------------------------------------------------

Transform an $n\times m$ Float Numeric array into an $n\times m$ Int0 Numeric array that will be
used to create an image. The float values are rescaled and cutted in order to range between 0 and 255.
The function returns the new Int0 array \var{mat} and the used values of \var{mn},
\var{mx} and \var{cd}.

\begin{itemize}
\item \var{mat}: input array ($n\times m$ Float Numeric array)
\item \var{scale}: scale "lin" or "log" (default=\var{log}) 
\item \var{cd}: scaling parameter (default=\var{0})
\item \var{mn}: minimum value for the cutoff (default=\var{None})   
\item \var{mx}: maximum value for the cutoff (default=\var{None})   
\end{itemize}

If \var{mn} or \var{mx} are not defined, they are set to the minimum and maximum value
of \var{mat}.

\begin{itemize}

\item 'lin' scale: 
\begin{equation}
  mat' = 255\, \frac{mat-mn}{mx-mn}
\end{equation}
In this case, \var{cd} is not used.

\item 'log' scale: 
\begin{equation}
  mat' = 255\, \frac{ln\left(1+\frac{mat-mn}{cd} \right)}{ln\left(1+\frac{mx-mn}{cd} \right)}
\end{equation}
If \var{cd} is not defined, it is set to the mean value of \var{mat}.

\end{itemize}

\begin{verbatim}
>>> from pNbody import *
>>> n = 256
>>> x,y = indices((n+1,n+1))
>>> x = 2*pi*(x-n/2)/(n/2)
>>> y = 2*pi*(y-n/2)/(n/2)
>>> R = sqrt(x**2+y**2)
>>> R1 = sqrt((x-pi)**2+(y-pi)**2)
>>> mat = cos(R)/(1+R) + 0.5*cos(R1)/(1+R1)
>>> mplot(mat)
>>> mat_int,mn,mx,cd = set_ranges(mat,scale='lin',mn=0,mx=0.5)
>>> mplot(mat_int)
\end{verbatim}
\end{funcdesc}



%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{contours}{m,matint,\optional{nl},\optional{mn},\optional{mx},\optional{kx},\optional{ky},\optional{color},\optional{crush}}
%--------------------------------------------------------------------------------------------------

Compute iso-contours on a $n\times m$ Float Numeric array.
Contours computed from \var{mat} are superposed on the integer matrix
\var{matint}.

\begin{itemize}
\item \var{mat}: input array ($n\times m$ Float Numeric array)
\item \var{matint}: input array ($n\times m$ Int Numeric array)
\item \var{l_n}: number of levels (default=\var{15}) 
\item \var{l_min}: minimum level value (default=\var{0})
\item \var{l_max}: maximum level value (default=\var{0})
\item \var{l_kx}: smoothing of contours in x (default=\var{10})
\item \var{l_ky}: smoothing of contours in y (default=\var{10})
\item \var{l_color}: color between 0 and 255 (default=\var{0})
\item \var{l_crush}: "yes"=remove background colors, "no"=keep background colors (default=\var{"no"})
\end{itemize}

If \var{l_min} equal \var{l_max}, levels are automatically between the minimum and
maximum values of the matrix \var{mat}. If \var{color}=0, no contour are displayed.

\begin{verbatim}
>>> from pNbody import *
>>> n = 256
>>> x,y = indices((n+1,n+1))
>>> x = 2*pi*(x-n/2)/(n/2)
>>> y = 2*pi*(y-n/2)/(n/2)
>>> R = sqrt(x**2+y**2)
>>> R1 = sqrt((x-pi)**2+(y-pi)**2)
>>> mat = cos(R)/(1+R) + 0.5*cos(R1)/(1+R1)
>>> mat_int,mn,mx,cd = set_ranges(mat,scale='lin')
>>> mat_int = contours(mat,mat_int,nl=30,mn=mn,mx=mx,kx=10,ky=10,color=1)
>>> mplot(mat_int)
>>> mat_int = contours(mat,mat_int,nl=30,mn=mn,mx=mx,kx=10,ky=10,color=1,crush='yes')
>>> mplot(mat_int)
\end{verbatim}
\end{funcdesc}



%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{add_box}{matint,\optional{shape=(256,256)},\optional{size=(30.,30.)},\optional{box_opts=(0,None,None,255)}}
%--------------------------------------------------------------------------------------------------

Superpose of box to the matrix \var{matint}.

\begin{itemize}
\item \var{matint}: input array ($n\times m$ Int Numeric array)
\item \var{shape}: shape of the matrix 
\item \var{size}: physical size of the matrix
\item \var{box_opts}: box options (lweight,xticks,yticks,color)
\end{itemize}

\begin{verbatim}
\begin{verbatim}
>>> from pNbody import *
>>> from numarray import random_array as RandomArray
>>> mat = RandomArray.random([256,256])
>>> mat = apply_filter(mat,name='convol',opt=[10,10,3,3])
>>> mat_int,mn,mx,cd = set_ranges(mat,scale='lin',mn=0,mx=0.5)
>>> mat_int = add_box(mat_int,shape=(256,256),size=(100,100),box_opts=(1,None,None,1))
>>> mplot(mat_int)
\end{verbatim}
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{mplot}{mat,\optional{palette='light'},\optional{save='no'}}
%--------------------------------------------------------------------------------------------------

Plot a or save the matrix array \var{mat}.

\begin{verbatim} 
>>> from pNbody import *
>>> from numarray import random_array as RandomArray
>>> mat = RandomArray.random([256,256])
>>> mplot(mat)
>>> mplot(mat,save='image.gif')
>>> mplot(mat,save='image.fits')
\end{verbatim} 
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{get_image}{mat,\optional{name},\optional{palette_name}}
%--------------------------------------------------------------------------------------------------

From the $n\times m$ Int Numeric array, create a PIL 
(Python Image Library) image.
If \var{name} is given, the image is saved on the disk.
\var{palette_name} is the name of the palette and is one of the following:
aips0,  backgr,  bgyrw,  blackwhite,  blue, blulut, color, green, half, heat,
idl11, idl12, idl14, idl15, idl2, idl4, idl5, idl6, isophot, light, lut0,
lut1, lut2, lut3, lut4, lut5, lut6, lut7, lut8, lut9, manycol, pastel, pmar,
rainbow, rainbow1, rainbow2, rainbow3, rainbow4, ramp, random, random1,
random2, random3, random4, random5, random6, real, red, smooth, smooth1,
smooth2, smooth3, staircase, stairs8, stairs9, standard, whiteblack
\begin{verbatim} 
>>> from pNbody import *
>>> from numarray import random_array as RandomArray
>>> mat = RandomArray.random([256,256])
>>> mat_int,mn,mx,cd = set_ranges(mat,scale='lin')
>>> image = get_image(mat_int,palette_name='rainbow4')
\end{verbatim} 
\end{funcdesc}




%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{display}{image}
%--------------------------------------------------------------------------------------------------

Display in a TK window the image \var{image} (PIL image).
\begin{verbatim}
>>> from pNbody import *
>>> from numarray import random_array as RandomArray
>>> mat = RandomArray.random([256,256])
>>> mat_int,mn,mx,cd = set_ranges(mat,scale='lin')
>>> image = get_image(mat_int,palette_name='rainbow4')
>>> display(image)
\end{verbatim}
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{sbox}{shape,size,\optional{lweight=1},\optional{xticks=None},\optional{yticks=None},\optional{color=255}}
%--------------------------------------------------------------------------------------------------

Return a matrix of integer, containing a box with labels
\end{funcdesc}
%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{drawxticks}{matint,m0,d0,n0,h0,shape,size,center,color}
%--------------------------------------------------------------------------------------------------

Return a matrix of integer, containing ticks in x.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{drawyticks}{matint,m0,d0,n0,h0,shape,size,center,color}
%--------------------------------------------------------------------------------------------------

Return a matrix of integer, containing ticks in y.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{getval}{nb,mode='m',obs=None}
%--------------------------------------------------------------------------------------------------

Return a specifc value extracted from the \class{pNbody} object \var{nb} according to the mode \var{mode}.
These function is used in the method \texttt{\textbf{ComputeMap}}.
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{getvaltype}{mode='m'}
%--------------------------------------------------------------------------------------------------

Return 'normal' or 'in projection' depending on the mode \var{mode}.
These function is used in the method \texttt{\textbf{ComputeMap}}.
\end{funcdesc}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{mpi module}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Output functions}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{mpi_pprint}{msg}
%--------------------------------------------------------------------------------------------------

Synchronized print.
\begin{verbatim}
[lunix@lunix ~/examples]$ mpirun -np 2 python scripts/mpi_pprint.py
[0] : hi !
[1] : hi !
\end{verbatim}
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{mpi_rprint}{msg}
%--------------------------------------------------------------------------------------------------

Rooted print.
\begin{verbatim}
[lunix@lunix ~/examples]$ mpirun -np 2 python scripts/mpi_rprint.py
hi !
hi !
\end{verbatim}
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{mpi_iprint}{msg}
%--------------------------------------------------------------------------------------------------

Synchronized print, including info on node.
\begin{verbatim}
[lunix@lunix ~/examples]$ mpirun -np 2 python scripts/mpi_rprint.py
hi, I am the master !
\end{verbatim}
\end{funcdesc}




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Communication functions}



%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{mpi_Bcast}{source,x}
%--------------------------------------------------------------------------------------------------

Broadcast from node \var{source} the variable \var{x}.
\begin{verbatim}
[lunix@lunix ~/examples]$ mpirun -np 2 python scripts/mpi_Bcast.py
[0] : hello from the master
[1] : hello from the master
\end{verbatim}
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{mpi_Send}{x,dest}
%--------------------------------------------------------------------------------------------------

Send \var{x} to node \var{dest}.
\begin{verbatim}
[lunix@lunix ~/examples]$ mpirun -np 2 python scripts/mpi_SendRecv.py
[1] : get 123 from node 0
\end{verbatim}
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{mpi_Recv}{source}
%--------------------------------------------------------------------------------------------------

Return a variable sent by node \var{source}.
\begin{verbatim}
[lunix@lunix ~/examples]$ mpirun -np 2 python scripts/mpi_SendRecv.py
[1] : get 123 from node 0
\end{verbatim}
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{mpi_reduce}{source}
%--------------------------------------------------------------------------------------------------

Reduce \var{x} from nodes.
\begin{verbatim}
[lunix@lunix ~/examples]$ pirun -np 2 python scripts/mpi_reduce.py
[0] : 3
[1] : 3
\end{verbatim}
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{mpi_Gather}{x,dest}
%--------------------------------------------------------------------------------------------------

Gather \var{x} from all nodes to node \var{dest}.
Returns a list.

\begin{verbatim}
[lunix@lunix ~/examples]$ mpirun -np 2 python scripts/mpi_Gather.py
[0] : None
[1] : [1, 2]
\end{verbatim}
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{mpi_AllGather}{x}
%--------------------------------------------------------------------------------------------------

Gather \var{x} from all nodes to all nodes.
Returns a list.

\begin{verbatim}
[lunix@lunix ~/examples]$ mpirun -np 2 python scripts/mpi_Allgather.py
[0] : [1, 2]
[1] : [1, 2]
\end{verbatim}
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{mpi_AllgatherAndConcatArray}{x}
%--------------------------------------------------------------------------------------------------

AllGather array \var{x} and concatenate it in a unique array
(concatenation order is reversed).

\begin{verbatim}
[lunix@lunix ~/examples]$ mpirun -np 2 python scripts/mpi_AllgatherAndConcatArray.py
[0] : [0 1 2]
[1] : [3 4 5]
[0] : [3 4 5 0 1 2]
[1] : [3 4 5 0 1 2]
\end{verbatim}
\end{funcdesc}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Array functions}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{mpi_sum}{x}
%--------------------------------------------------------------------------------------------------

Sum elements of array \var{x}.

\begin{verbatim}
[lunix@lunix ~/examples]$ mpirun -np 2 python scripts/mpi_sum.py
[0] : [0 1 2]
[1] : [3 4 5]
[0] : 15
[1] : 15
\end{verbatim}
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{mpi_min}{x}
%--------------------------------------------------------------------------------------------------

Minimum element of array \var{x}.

\begin{verbatim}
[lunix@lunix ~/examples]$ mpirun -np 2 python scripts/mpi_minmax.py
[0] : [0 1 2]
[1] : [3 4 5]
[0] : min= 0
[1] : min= 0
[0] : max= 5
\end{verbatim}
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{mpi_max}{x}
%--------------------------------------------------------------------------------------------------

Maximum element of array \var{x}.

\begin{verbatim}
[lunix@lunix ~/examples]$ mpirun -np 2 python scripts/mpi_minmax.py
[0] : [0 1 2]
[1] : [3 4 5]
[0] : min= 0
[1] : min= 0
[0] : max= 5
\end{verbatim}
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{mpi_mean}{x}
%--------------------------------------------------------------------------------------------------

Mean of elements of array \var{x}.

\begin{verbatim}
[lunix@lunix ~/examples]$ mpirun -np 2 python scripts/mpi_mean.py
[0] : [ 0.  1.  2.]
[1] : [ 3.  4.  5.]
[0] : mean= 2.5
[1] : mean= 2.5
\end{verbatim}
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{mpi_len}{x}
%--------------------------------------------------------------------------------------------------

Lenght of array \var{x}.

\begin{verbatim}
[lunix@lunix ~/examples]$ mpirun -np 2 python scripts/mpi_len.py
[0] : [0 1 2]
[1] : [3 4 5]
[0] : len= 6
[1] : len= 6
\end{verbatim}
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{mpi_arange}{n}
%--------------------------------------------------------------------------------------------------

Create an integer array containing elements from 0 to \var{n}
spreaded over all nodes.

\begin{verbatim}
[lunix@lunix ~/examples]$ mpirun -np 2 python scripts/mpi_arange.py
[0] : [10 11 12 13 14 15 16 17 18 19]
[1] : [0 1 2 3 4 5 6 7 8 9]
\end{verbatim}
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{mpi_arange}{nall}
%--------------------------------------------------------------------------------------------------

Create an integer array containing elements from 0 to \var{n}
spreaded over all nodes. The repartition of elements and type of elements over nodes is given by
the array \var{nall}.

\begin{verbatim}
[lunix@lunix ~/examples]$ mpirun -np 2 python scripts/mpi_sarange.py
[0] : [ 5  6  8  9 10]
[1] : [0 1 2 3 4 7]
\end{verbatim}
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{mpi_argmax}{x}
%--------------------------------------------------------------------------------------------------

Find arument of the maximum value in x.

\begin{verbatim}
[lunix@lunix ~/examples]$ mpirun -np 2 python scripts/mpi_argfind.py
\begin{verbatim}
[lunix@lunix ~/examples]$ mpirun -np 2 python scripts/mpi_argfind.py
[0] : [3 0 4]
[1] : [2 5 6]
[0] : (0, 1)
[1] : (0, 1)
[0] : (1, 2)
[1] : (1, 2)
[0] : 0
[1] : 0
[0] : 6
[1] : 6
\end{verbatim}
\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{mpi_argmin}{x}
%--------------------------------------------------------------------------------------------------

Find arument of the mimimum value in x.

\begin{verbatim}
[lunix@lunix ~/examples]$ mpirun -np 2 python scripts/mpi_argfind.py
\begin{verbatim}
[lunix@lunix ~/examples]$ mpirun -np 2 python scripts/mpi_argfind.py
[0] : [3 0 4]
[1] : [2 5 6]
[0] : (0, 1)
[1] : (0, 1)
[0] : (1, 2)
[1] : (1, 2)
[0] : 0
[1] : 0
[0] : 6
[1] : 6
\end{verbatim}
\end{funcdesc}


%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{mpi_getval}{x,idx}
%--------------------------------------------------------------------------------------------------

Return the value of array \var{x} corresponding to the index \var{idx}.

\begin{verbatim}
[lunix@lunix ~/examples]$ mpirun -np 2 python scripts/mpi_argfind.py
\begin{verbatim}
[lunix@lunix ~/examples]$ mpirun -np 2 python scripts/mpi_argfind.py
[0] : [3 0 4]
[1] : [2 5 6]
[0] : (0, 1)
[1] : (0, 1)
[0] : (1, 2)
[1] : (1, 2)
[0] : 0
[1] : 0
[0] : 6
[1] : 6
\end{verbatim}
\end{funcdesc}



%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{mpi_histogram}{x,binx}
%--------------------------------------------------------------------------------------------------

Return an histogram of vector \var{x} binned using \var{binx}.

\begin{verbatim}
[lunix@lunix ~/examples]$ mpirun -np 2 python scripts/mpi_histogram.py
[0] : [ 0.84406817  0.36298877  0.97603917  0.93461412  0.79251379
  0.34625384  0.68936312  0.34766984  0.00754931  0.18829931]
[1] : [ 0.84404922  0.59192866  0.99656236  0.06286281  0.48847792
  0.51723957  0.44006979  0.10298632  0.3450942   0.56593537]
[0] : [ 0.    0.25  0.5   0.75]
[1] : [ 0.    0.25  0.5   0.75]
[0] : [4 6 4 6]
[1] : [4 6 4 6]
\end{verbatim}
\end{funcdesc}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{io functions}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{mpi_ReadAndSendBlock}{f,data_type,\optional{shape=None},\optional{byteorder=sys.byteorder},\optional{split=None}}
%--------------------------------------------------------------------------------------------------

Read and brodcast a binary block.

\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{mpi_ReadAndSendArray}{f,data_type,\optional{shape=None},\optional{skip=None},\optional{byteorder=sys.byteorder},\optional{nlocal=None}}
%--------------------------------------------------------------------------------------------------

Read and brodcast a binary block assuming it contains an array.
The array is splitted acroding to the variable \var{nlocal}.

\end{funcdesc}

%--------------------------------------------------------------------------------------------------
\begin{funcdesc}{mpi_GatherAndWriteArray}{f,data_type\optional{byteorder=sys.byteorder},\optional{nlocal=None}}
%--------------------------------------------------------------------------------------------------

Gather and array and write it in a binary block.

\end{funcdesc}







%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{ic module}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{io module}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{cosmo module}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{thermodyn module}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{geometry module}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Associated programs}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{gwin}

\subsection{Description}

\bfcode{gwin} allows to display an \class{pNbody} object with a user friendly interface.
It contains all possibilities of selection/filtering/exposition/stereo
offered by the module \class{pNbody}. 

\subsection{Usage}
\begin{verbatim}
usage: gwin [options] file

options:
  -h, --help        show this help message and exit
  -t  TYPE          type of the file
  --stereo          enable stereo view
  -p  PALETTE NAME  palette name
  -f  FILE NAME     parameter file
  -u  FILE NAME     unitsparameter file
  --fullscreen      fullscreen mode
  --pio             parallel io mode

\end{verbatim}

\subsection{Example}

\begin{verbatim}
[lunix@lunix ~/examples]$ gwin -t gadget gadget_z00.dat
\end{verbatim}

\clearpage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{gpy}

\subsection{Description}

\bfcode{gpy} allows open an \class{pNbody} object and enter the python interpreter,
where you can interact with the object using the variable \var{nb}.

\subsection{Usage}
\begin{verbatim}
usage: gpy [options] file

options:
  -h, --help      show this help message and exit
  -t  TYPE        type of the file
  --exec= STRING  give command to execute before

\end{verbatim}

\subsection{Example}

\begin{verbatim}
[lunix@lunix ~/examples]$ gpy -t gadget disk.dat
>>> len(nb.mass)
3001
\end{verbatim}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{gcmd}

\subsection{Description}

Perfome a serie of operations on a list of files.


\subsection{Usage}
\begin{verbatim}
usage: gcmd [options] file

options:
  -h, --help      show this help message and exit
  -t  TYPE        type of the file
  --exec= STRING  give command to execute before making the image
\end{verbatim}


\subsection{Examples}

\begin{verbatim}
[lunix@lunix ~/examples]$ gcmd -t gadget gadget_z00.dat gadget_z40.dat --exec='''print nb.p_name[0]; print "a=%7.3f"%nb.atime'''
gadget_z00.dat
a=  1.000
gadget_z40.dat
a=  0.027
\end{verbatim}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{gimage}

\subsection{Description}

Create an image from a model file.


\subsection{Usage}
\begin{verbatim}
usage: gimage [options] file

options:
  -h, --help            show this help message and exit
  -f  FILE NAME         parameter file
  -u  FILE NAME         unitsparameter file
  -t  TYPE              type of the file
  -o  STRING            oputput file name
  --mode= STRING        observable mode
  --palette= STRING     palette name
  --mn= FLOAT           min value
  --mx= FLOAT           max value
  --cd= FLOAT           cd value
  --scale= STRING       scale
  --view= STRING        view xy,xz,yz
  --space= STRING       space pos,vel
  --filter_name= STRING
                        filter name
  --filter_opts= STRING
                        filter opts
  --shape= STRING       shape (x,y)
  --size= STRING        size (x,y)
  --exec= STRING        give command to execute before making the image
\end{verbatim}


\subsection{Examples}

\begin{verbatim}
[lunix@lunix ~/examples]$ gimage -t gadget gadget_z00.dat --palette='rainbow4' --mode='T' \
? --shape='(256,256)' --size='(10000,10000)' --exec='''nb = nb.select("gas")''' -o image.gif
min= 0.000e+00 max= 6.487e+12 cd= 1.114e+10
\end{verbatim}



\clearpage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{ginter}

\subsection{Description}


\subsection{Usage}
\begin{verbatim}
\end{verbatim}


\subsection{Examples}

\begin{verbatim}
\end{verbatim}


\clearpage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{mkgmov}

\subsection{Description}

\bfcode{mkgmov} allows to create \bfcode{gmov} movie from a list of \class{Nbody} files.

\subsection{Usage}
\begin{verbatim}  
Options: -h        -- this help message
           -p        -- parameter file
           -f        -- g-parameter file
           -s        -- disable the softening of rsp
           -c        -- enable auto cd for each image
           -z        -- convert time in redshift
           --info    -- give the optimal factor for each files in the list
           --help    -- this help message
           --version -- displays version
\end{verbatim}

\subsection{Example}

\begin{verbatim}
[lunix@lunix ~/examples]$ cd films/
[lunix@lunix ~/films]$ mkgmov -p filmparam.py film.gmv treo*
\end{verbatim}

\subsection{Parameter file}

To create a movie, the best is to provide \bfcode{mkgmov} a parameter file. Such an example is
given below:

\begin{verbatim}
# number of horizontal and vertical subfilms
nh = 1  # horizontal								     
nw = 2	# vertical
							     
# size of subfilms						     
width = 256							     
height = 256
				     
# size of the film						     
numByte = width * nw						     
numLine = height * nh						     						     
# init parameters						     
param = initparams(nh,nw)	 


# params 1
param[1]['ftype'] = 'binary'
param[1]['view'] = 'xy'
param[1]['mode'] = 'm'
param[1]['size'] = (35.,35.)


# params 2
param[2]['ftype'] = 'binary'
param[2]['x0'] = [0,-1e-5,50]
param[2]['xp'] = [0,0,0]
param[2]['size'] = (35.,35.)
param[2]['exec'] = '''nb = nb.selectp(file='sub.txt')'''
param[2]['mode'] = 'vr'
param[2]['filter_name'] = 'convol'
param[2]['mn'] = -0.14
param[2]['mx'] = 0.14
param[2]['cd'] = 0.0002346
\end{verbatim}

First, we have to give the number of horizontal \texttt{nh} and vertical \texttt{nv} subfilms.
Then, the \texttt{width} and \texttt{height} of each subfilms. The next five lines must remain
untouched :
\begin{verbatim}
# size of the film						     
numByte = width * nw						     
numLine = height * nh						     						     
# init parameters						     
param = initparams(nh,nw)	 
\end{verbatim}

Then, for each subfilm, we have to define parameters to use. The parameter corresponds 
to the parameter of the function \bfcode{show} described in the paragraph~\ref{graphfuncts}.
Each parameter is given with a line of the type:
\begin{center}
\texttt{param[} \var{subfilm number} \texttt{][}\var{parameter name}\texttt{]=}\var{value}
\end{center}

\begin{itemize}
\item \var{subfilm number}:	number of the subfilm, from $1$ to \texttt{nh}$\times$\texttt{nv}
\item \var{parameter name}:	parameter name (see function \bfcode{show})
\item \var{value}: 		value of the parameter
\end{itemize}



\subsection{Notes}

\begin{itemize}

\item compare to command \bfcode{show} additional parameters are :

    \begin{tableii}{l|l}{code}{Value}{Meaning}
    \lineii{\var{exec}}{execute a command}
    \lineii{\var{macro}}{execute a macro (path of the file)}
    \lineii{\var{n1}}{first particle}
    \lineii{\var{n2}}{last particle}
    \lineii{\var{mdis}}{select particle in function of the value of \var{dis} (see function \bfcode{subdis})}
    \lineii{\var{ftype}}{type of the file}
    \hline
    \end{tableii}

\item parameters \var{palette} and \var{save} are not take into account.

\item If \var{dark} is given as a value form the parameter \var{mode}, the corresponding submovie
will simply be black. 

\item The option \texttt{--info} do not write any output. It simply gives the minimum and maximum value,
as well as the optimum parameter \var{cd} of each frame. This is often useful to run \bfcode{mkgmov} first with option
\texttt{--info}, before choosing the values of \var{mn}, \var{mx} and \var{cd}.  

\end{itemize}

\clearpage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{gmov}

\subsection{Description}

This program is used to show \bfcode{gmov} movie files created for example with \bfcode{mkgmov}.

\subsection{Usage}
\begin{verbatim}
usage: gmov [options] file

options:
  -h, --help            show this help message and exit
  -f, --fullscreen      fullscreen mode
  -a, --auto            automatically run the movie
  --nopalette           do not display the palette
  --nocontroll          do not display the controll pannel
  --notime              do not display the time
  -p  PALETTE NAME      palette name
  -z  INT               zoom factor
  -s  INT               speed
  -i                    read the whole film before displaying it (get info)
  --stepsize= INT       size of step
  --delay= FLOAT        delay before starting in auto mode
  --presentation        choose parameters for presentation
  --loop                loop on
  -b  COLOR, --background= COLOR
                        palette name

\end{verbatim}

\subsection{Main window}

The main window (see Fig.~\ref{gmov1}) allows to control the movie. Main functions are:
\begin{itemize}
\item \texttt{RUN}:    		Run the movie from the frame \texttt{start.pic} to the frame \texttt{stop.pic}.
				Use it only when the film is stopped. 
\item \texttt{STOP}:    	Stop the movie.
\item \texttt{STEP}:   	 	Move to the next frame, step by step. Use it only when the film is stopped.
\item \texttt{BACK}:    	Move to the previous frame, step by step. Use it only when the film is stopped.
\item \texttt{RESET}:		Go to the \texttt{start.pic} frame.
\item \texttt{QUIR}:		Quit
\item \texttt{ZOOM}:		Zoom in.
\item \texttt{UNZOOM}:		Zoom out.
\item \texttt{RESET ZOOM}:	Disable zoom. 
\end{itemize}

       \begin{figure}[!]
       \begin{center}
       \includegraphics[width=10cm]{graph/gmov1.ps}
       \caption{Main window of gmov.}
       \label{gmov1}
       \end{center}
       \end{figure}

       \begin{figure}[!]
       \begin{center}
       \includegraphics[width=5.18cm]{graph/gmov2.ps}
       \caption{Display window of gmov.}
       \label{gmov2}
       \end{center}
       \end{figure}


The \texttt{filename} entry display the name of the current film. A new film can be loaded by
modifying the name and pressing \emph{enter}.


\subsection{Menus}

\subsubsection{File}

\begin{itemize}
\item \texttt{open}: 		Open a new film.
\item \texttt{reload}: 		Reopen the film.
\item \texttt{save image}: 	Save an image (format must be .gif, .fits or .png).
\item \texttt{quit}: 		quit the application
\end{itemize}

\subsubsection{Colormap}

Change the color map.

\subsubsection{Speed}

Change the speed of the movie. $1$ is the fastest, $100$ is the slowest.

\subsubsection{Zoom}

Zoom in or zoom out.

\subsection{Examples}

\begin{verbatim}
[lunix@lunix ~/films]$ gmov film.gmv
\end{verbatim}



\clearpage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{infogmov}

\subsection{Description}

Give info from a given film.


\subsection{Usage}
\begin{verbatim}
infogmov -f film [options]

  This function gives info on a film

  Options: -h        -- this help message
           -f        -- name of the input
           --help    -- this help message
           --version -- displays version

\end{verbatim}


\subsection{Examples}

\begin{verbatim}
[lunix@lunix ~/films]$  infogmov -f film.gmv

    -- film.gmv  --

    initial time            :  500.000
    final   time            : 2000.000
    dt                      :  500.000
    number of images        : 4
    number of collumns      : 256
    number of lines         : 512
    length of header        : 256

\end{verbatim}


\clearpage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{cutgmov}

\subsection{Description}

From a given film, \bfcode{cutgmov} creates a new
film that contains only frames from \var{n1} to \var{n2}.

\subsection{Usage}
\begin{verbatim}
cutgmov -f filmin -o filmout --n1=n1 --n2=n2

  Options: -h        -- this help message
           -f        -- name of the input
           -o        -- name of the output
           --n1      -- number of the first frame
           --n2      -- number of the last frame
           --info    -- give info on the film
           --help    -- this help message
           --version -- displays version

\end{verbatim}

\subsection{Examples}

\begin{verbatim}
[lunix@lunix ~/films]$ cutgmov -f film.gmv -o film_cutted1.gmv --n1=0 --n2=2
0
1
[lunix@lunix ~/films]$ cutgmov -f film.gmv -o film_cutted2.gmv --n1=2 --n2=4
0
1
2
3
\end{verbatim}



\clearpage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{addgmov}

\subsection{Description}

\bfcode{addgmov} concatenates a number of films of same 
geometry. The lenght of the films may be different. 

\subsection{Usage}
\begin{verbatim}
addgmov -o outfilm film1 film2 ...

  Options: -h        -- this help message
           -o        -- name of the output
           --help    -- this help message
           --version -- displays version
\end{verbatim}

\subsection{Examples}

\begin{verbatim}
[lunix@lunix ~/films]$ addgmov -o film_new.gmv  film_cutted1.gmv film_cutted2.gmv
500.0
1000.0
1500.0
2000.0
\end{verbatim}


\clearpage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{splitgmov}

\subsection{Description}

\bfcode{splitgmov} split each frame of a movie in \var{nh}$\times$\var{nv}
subframes. \var{nh} is the number of horizontal subframes while 
\var{nv} is the number of vertical subframes.
In output, \bfcode{splitgmov} return \var{nh}$\times$\var{nv} new movies 
made with the subframes. Each new movie is named with the name of the input
movie, followed by the corresponding value of \var{nh} and \var{nv}.


\subsection{Usage}
\begin{verbatim}
splitgmov -f input --nh=nh --nv=nv

  Options: -h        -- this help message
           -f        -- input movie
           --nh      -- number of horizontal images
           --nv      -- number of vertical images
           --help    -- this help message
           --version -- displays version
\end{verbatim}


\subsection{Examples}

\begin{verbatim}
[lunix@lunix ~/films]$ splitgmov -f film.gmv --nh=1 --nv=2
500.0
1000.0
1500.0
2000.0
\end{verbatim}

\clearpage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{mergegmov}

\subsection{Description}

\bfcode{mergegmov} do the opposit as \bfcode{splitgmov}. In input, it
takes \var{nh}$\times$\var{nv} films of identical geometry and lenght.
It returns a new film composed out of it.

\subsection{Usage}
\begin{verbatim}
mergegmov -o output --nh=nh --nv=nv film1 film2 ...
  
  Options: -h        -- this help message
           -o        -- name of the output
           --nh      -- number of horizontal images
           --nv      -- number of vertical images
           --help    -- this help message
           --version -- displays version
\end{verbatim}

\subsection{Examples}

\begin{verbatim}
[lunix@lunix ~/films]$ mergegmov -o film_new.gmv --nh=2 --nv=1 film_11.gmv film_12.gmv
0 / 3
1 / 3
2 / 3
\end{verbatim}


\clearpage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{combinegmov}

\subsection{Description}

\bfcode{combinegmov} put on top of each other images from two different films of same shape and
same number of frames.

\subsection{Usage}
\begin{verbatim}
Usage : combinegmov -o output film1 film2
  Options: -h        -- this help message
           -o        -- name of the output
           --help    -- this help message
           --version -- displays version
	   
\end{verbatim}

\clearpage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{supgmov}

\subsection{Description}

\bfcode{supgmov} put on top of each other images from several different films of same shape and
same number of frames.

\subsection{Usage}
\begin{verbatim}
Usage : supgmov -o outfilm film1 film2 film3...
  Options: -h        -- this help message
           -o        -- name of the output
           --help    -- this help message
           --version -- displays version

	   
\end{verbatim}

\clearpage

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{gmov2gif}

\subsection{Description}

\bfcode{gmov2gif} create a \emph{gif} movie from the input film.

\subsection{Usage}
\begin{verbatim}
gmov2gif -f file [options ...]
  Options: -h        -- this help message
           -f        -- input file
           -o        -- output file
           -p        -- name of a palette
           -z        -- zoom factor
           -d        -- pause between images (ms)
           -b        -- number of initial image
           -e        -- number of final image
           -s        -- number of images to leap
           -l        -- add the label (time)
           -i        -- gives information on the film
           -k        -- keep temporary images
           -t        -- add a text
           --version -- displays version

\end{verbatim}

\subsection{Note}

This scripts needs the program \program{convert} to be installed.

\subsection{Examples}

\begin{verbatim}
[lunix@lunix ~/films]$ gmov2gif -f film.gmv -o film.gif -p rainbow4
tmp/0000_0500.000
tmp/0001_1000.000
tmp/0002_1500.000
tmp/0003_2000.000
convert -delay 10 tmp/*.gif film.gmv.gif
\end{verbatim}



\clearpage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{gmov2mpeg}

\subsection{Description}

\bfcode{gmov2gif} create an \emph{mpeg} movie from the input film.

\subsection{Usage}
\begin{verbatim}
Usage : gmov2mpeg -f file [options ...]
  Options: -h        -- this help message
           -f        -- input file
           -o        -- output file
           -p        -- name of a palette
           -z        -- zoom factor
           -d        -- pause between images (ms)
           -b        -- number of initial image
           -e        -- number of final image
           -s        -- number of images to leap
           -l        -- add the label (time)
           -i        -- gives information on the film
           -k        -- keep temporary images
           -t        -- add a text
           --cosmo   -- cosmoligical option
           --version -- displays version
\end{verbatim}

\subsection{Note}

This scripts needs the program \program{convert} and \program{ppmtompeg} 
to be installed.

\begin{verbatim}
[lunix@lunix ~/films]$ gmov2mpeg -f film.gmv -o film.gif -p rainbow4
tmp/0000_0500.000
tmp/0001_1000.000
tmp/0002_1500.000
tmp/0003_2000.000
...
\end{verbatim}


\clearpage


                                                 


%\appendix
%\chapter{...}
%
%My appendix.
%
%The \code{\e appendix} markup need not be repeated for additional
%appendices.


%
%  The ugly "%begin{latexonly}" pseudo-environments are really just to
%  keep LaTeX2HTML quiet during the \renewcommand{} macros; they're
%  not really valuable.
%
%  If you don't want the Module Index, you can remove all of this up
%  until the second \input line.
%
%begin{latexonly}
\renewcommand{\indexname}{Module Index}
%end{latexonly}
%\input{mod\jobname.ind}		% Module Index

%begin{latexonly}
\renewcommand{\indexname}{Index}
%end{latexonly}
%\input{\jobname.ind}			% Index

\end{document}
