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. (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. 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 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 in the same order with which they have been declared in param. 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. 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 ( i <= 0 ) i=io_nemo_f(infile,80,MAXBODY,"real8,3n,read,n,m,x,v,t,info", $ 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",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. 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.
FFLAGS = -fno-second-underscore -fwritable-strings
# ---------------------------------------- # MAKEFILE to use IO_NEMO_F # # ---------------------------------------- # path for NEMO Library and IO_NEMO_F library LIBS = -L$(NEMOLIB) -L/usr/local/lib FFLAGS = $(OPT) -fno-second-underscore -fwritable-strings nemo_fortran : nemo_fortran.o $(FC) -o $@ nemo_fortran.o $(LIBS) \ -lio_nemo_f -lm # ----------------------------------------
nemo(1NEMO), snapshot(5NEMO).
15-Jun-95 V1.0 : created JCL 21-Jun-95 V1.1 : bugs fixes JCL 12-Dec-95 V1.2 : possibility to close file JCL 11-Mar-96 V1.3 : acceleration I/O added JCL 04-Apr-97 V1.4 : generic real format JCL 07-Apr-97 V1.41: manual created JCL 09-Apr-97 V1.42: manual corrections AS