Note that this program write all variables as float (single precision), including integers.
For an alternative approach, use snappat(1NEMO) to create a Particle-Attribute-Time datacube, convert this to FITS using ccdfits(1NEMO) and read this into IDL. For simulations with a large number of snapshots this can be significantly faster.
Nb,T1,Nv,v1,v2,v3,....v_Nv,Nb,T2,Nv,v1,v2,v3,....v_Nv,....where Nb is the number of bodies and Nv the number of vectors of length Nb each.
mkplummer snap000 100 idl IDL> SPAWN, [’snapidl’,’snap000’,’x,y,z’], UNIT=LUN, /NOSHELL IDL> nbody=0L IDL> nvec=0L IDL> READU,LUN,nbody,nvec,tsnap IDL> PRINT,"Found a snapshot with ",nbody," particles at time", tsnap IDL> x=FLTARR(nbody) IDL> y=FLTARR(nbody) IDL> z=FLTARR(nbody) IDL> READU,LUN,x,y,z IDL> FREE_LUN, LUN
And here is an example writing the data in a format that can be read with
a fortran program:
mkplummer snap111 100 snapidl snap111 x,y,z out=snap111.dat fortran=t idl IDL> OPENR,LUN,’snap111.dat’,/F77_UNFORMATTED,/GET_LUN IDL> nbody=0L IDL> nvec=0L IDL> READU,LUN,nbody,nvec,tsnap IDL> PRINT,"Found a snapshot with ",nbody," particles at time", tsnap IDL> x=FLTARR(nbody) IDL> y=FLTARR(nbody) IDL> z=FLTARR(nbody) IDL> READU,LUN,x IDL> READU,LUN,y IDL> READU,LUN,z IDL> FREE_LUN, LUNIn fortran, without any error control and array overflow checking, snap111.dat can also be read as follows:
program snapread real x(1000),y(1000),z(1000),tsnap integer nbody,nvec,i open(1,file=’snap111.dat’,form=’unformatted’) read(1) nbody,nvec,tsnap read(1) (x(i),i=1,nbody) read(1) (y(i),i=1,nbody) read(1) (z(i),i=1,nbody) end
Careful cutting and pasting examples from man pages, hidden characters can slip unseen into your session.
26-Nov-02 V1.0 Created PJT 5-aug-09 it seems IDL now needs /GET_LUN in the 2nd example 6-aug-09 V1.2 added header= PJT