This HTML automatically generated with rman for NEMO
Table of Contents

Name

io_nemo_f -- High level C function to read/save NEMO snapshot from a FORTRAN program.

Synopsis


io_nemo_f(filename, slen, MAXBODY, param, ....)
character * filename(*);/* input/output file name */
integer     slen;       /* #characters in ’infile’ */
integer     MAXBODY;    /* maximun bodies allowed */
character * param(*);   /* parameters list */

Descriptionio_nemo_f is a high level C function which allows the user to
perform I/O operations on NEMO snapshot files from a FORTRAN program.  The
use of this function is very simple and doesn’t require any knowledge of
how to program in NEMO. 

Parameters 
 filename=character variable Input/Output file name of the NEMO snapshot
that you want to read/save. (this CHARACTER string must be a VARIABLE, not
a constant !). slen=integer Lenght of the file name.  (We need this information
because of the interface bettween FORTRAN and C language) MAXBODY=integer
Size of array that you use to get/put the data. Match the size of the array
to the maximum number of bodies that you are able to read/save.  param=character
Param is a string in which you specify what you want to do with the NEMO
file. Each choice is defined with a flag separated with ’,’. There are two
kind of flags. (1) Information flags allow to specify some actions during
the I/O. (2) Variables flags allow to specify what you want to get/put from/into
the NEMO file. The FLAGS list is described below. DO NOT FORGET TO ADD A
\0 at the end of Param variable as you can see in the example below. 
(1)
Information flagss | save Specify that you want to save data to a NEMO file.
r | read Specify that you want to read data from a NEMO file. real4|single
Specify that the variables that you use to get/put data from/into NEMO
files have been declared in single precision. (real * 4). real8|double Specify
that the variables you use to get/put data from/into NEMO files have been
declared in double precision. (real * 8). f | n3 Assumes that you declared
yours two-dimensionnal FORTRAN arrays (pos, vel, acc) using the number of
bodies for the first dimension and the number of space coordinates (always
3D) for the second dimension. (example : real * 4 pos(10000,3) ). c | 3n Assumes
that you declared yours two-dimensionnal FORTRAN arrays (pos, vel, acc)
using the number of space coordinates (always 3D)  for the first dimension
and the number of bodies for the second dimension. (example : real * 4 vel(3,10000)
). info | diag Gives some informations during the runtime execution.  
(2)
Variables flags n|nbody Match to the number of bodies. t|time Match to the
snapshot time. m|mass Match to the particle masses. x|pos Match to the particle
positions. v|vel Match to the particle velocities. p|pot Match to the particle
potentials. a|acc Match to the particle accelerations. aux Match to the auxiliary
array. k|keys Match to the keys array. d|dens Match to the particle density.
e|eps Match to the particle softening.  st Select snapshot’s times. You have
to  put the selected time in a string limited by the character ’#’. Example
"100:150#" select the time beween 100 and 150. The string is fully compatible
with the expression usually given to nemoinpi (Cf man nemoinpi).  sp Select
snapshot’s particles. You have to  put the selected particles in a string
limited by the character ’#’. Example "0:299999#" select the particles beween
0 and 299999. The returned nbody corresponds to the selected nbody. In the
example above it would thus be 300000. The string is fully compatible with
the expression usually given to nemoinpi (Cf man nemoinpi).   
ArgumentsThe
variable flags specify which data you will get/put from/into the NEMO file,
hence after the selection string param, you must insert all the selected
variables (arguments) in the same order with which they have been declared
in param.  Return ValueThe function return 1 if successfull, 0 if the end
of snapshot has been reached.  ExampleHere is a FORTRAN program to illustrate
the use of the function io_nemo_f(). The program reads all the time steps
into a NEMO a file, and saves the data in another NEMO file. Source file
of the example below is located here: $NEMOSRC/nbody/io_nemo/test_src/nemo_fortran_d_3n.F

C----------------------------------------------------------- 
      program nemo_fortran
      implicit none
c maximum # of bodies
      integer MAXBODY    
      parameter (MAXBODY=100000)
      real*8  
c particle masses.
     +     mass(1:MAXBODY),
c particle positions and velocities    
     +     pos(3,MAXBODY), vel(3,MAXBODY),
c snapshot time
     +     ts
c file names
      character infile*80,outfile*80
      integer i,j,k,nbody,io_nemo_f,close_io_nemo_f
c get input snapshot filename
      write(*,*)’Infile name : ’
      read(*,’(a80)’)infile
c get output snapshot filename
      write(*,*)’outfile name : ’
      read(*,’(a80)’)outfile
      i = 1
      do while (i.gt.0) 
c read the snapshot up to the end of file 
c at the end of snapshot, io_nemo_f return 0
         i=io_nemo_f(infile,80,MAXBODY,"real8,3n,read,n,m,x,v,t,info\0",
     $        nbody,mass,pos,vel,ts)
c save the snapshot
         if (i.gt.0) then
            j=io_nemo_f(outfile,80,MAXBODY,"real8,3n,save,n,m,x,v,t, 
     $           info\0",nbody,mass,pos,vel,ts)
         endif
      end do
c close the snapshot ’outfile’
      k= close_io_nemo_f(outfile,80)
      end
C----------------------------------------------------------- 

Important Thingsa) Notice in the example above, that in the parameter list,
’n’ matches ’nbody’, ’m’ matches ’mass’, ’x’ matches ’pos’, ’v’ matches ’vel’, ’t’ matches
’ts’.  All the variables are in the same order that they have been declared
in the param list. Notice also that you must add \0 at the end of Param variable
"real8,3n,read,n,m,x,v,t,info\0".  b) You must declare all the two-dimensionnal
arrays in the same way. That means all the dimensions must be the same for
all the arrays, moreover both one-dimensional and two-dimensional array must
have the same size for the maximum of bodies.  c) All the arrays must be
declared in the same floating type.  d) During a "read" operation, the function
io_nemo_f() return ’0’ if it is the end of the NEMO file. That means that
no new values have been read.  

Compilation

To use the function io_nemo_f() from a FORTRAN program you must link your program with the library libnemo.a as described in the Makefile below. Notice that there are specials compilation flags and linking options according to you use g77 compiler or gfortran compiler or ABSOFT fortran compiler.


# ----------------------------------------
# MAKEFILE to use IO_NEMO_F
# 
# ----------------------------------------
# path for NEMO Library and IO_NEMO_F library
LIBS = -L$(NEMOLIB)
# - - - - - - - - - - - - - - - - - - - -
# compilation with g77 compiler
# - - - - - - - - - - - - - - - - - - - -
G77FLAGS = -fno-second-underscore -Wno-globals
nemo_fortran_g77 : nemo_fortran.F
    g77 $(G77FLAGS)  -o $@ nemo_fortran.F $(LIBS) \
                  -lnemomaing77 -lnemo -lm
# - - - - - - - - - - - - - - - - - - - -
# compilation with gfortran compiler
# - - - - - - - - - - - - - - - - - - - -
GFORTFLAGS = -fno-second-underscore
nemo_fortran_g77 : nemo_fortran.F
    gfortran $(GFORTFLAGS)  -o $@ nemo_fortran.F $(LIBS) \
                  -lnemomaing77 -lnemo -lm
# - - - - - - - - - - - - - - - - - - - -
# compilation with absoft f77 compiler
# - - - - - - - - - - - - - - - - - - - -
ABFFLAGS = -B108 -K
nemo_fortran_ABSOFT : nemo_fortran.F
    $(ABSOFT)/bin/f77 $(ABFFLAGS)  -o $@ nemo_fortran.F $(LIBS) \
                   -lnemo -lm
# ----------------------------------------

See Also


nemo(1NEMO), snapshot(5NEMO).

Author

Jean-Charles LAMBERT

BUGS and COMMENT

Please, report all bugs and comment to :
Jean-Charles.Lambert@oamp.fr

Update History


15-Jun-95    V1.0 : created                        JCL
21-Jun-95    V1.10: bugs fixes                     JCL
12-Dec-95    V1.11: possibility to close file      JCL
11-Mar-96    V1.12: acceleration I/O added         JCL
04-Apr-97    V1.13: generic real format            JCL
07-Apr-97    V1.14: manual created                 JCL 
19-Jul-02    V1.20: io_nemo/io_nemo_f unified      JCL 
18-Mar-04    V1.21: bugs fixed, softening added    JCL
03-Mar-05    V1.30: code cleaning, valgrind safe   JCL
24-Apr-06    V1.31: memory leak fixed              JCL
19-Jun-06    V1.32: happy gfortran                 JCL
29-May-07    V1.42: handle snapshot with different JCL
                   nbodies
29-Feb-08    V1.50: add Aux and Dens array         JCL


Table of Contents