subroutine read_particles_snapshot(file_exists)
use mod_global_parameters
logical,intent(out) :: file_exists
character(len=std_len) :: filename
integer :: mynpayload, mynparticles, pos
! some initialisations:
nparticles_on_mype = 0
mynparticles = 0
nparticles = 0
it_particles = 0
! open the snapshot file on the headnode
file_exists=.false.
if (mype == 0) then
! write(filename,"(a,a,i4.4,a)") trim(base_filename),'_particles',snapshotini,'.dat'
! Strip restart_from_filename of the ending
pos = scan(restart_from_file, '.dat', back=.true.)
write(filename,"(a,a,i4.4,a)") trim(restart_from_file(1:pos-8)),&
'_particles',snapshotini,'.dat'
INQUIRE(FILE=filename, EXIST=file_exists)
if (.not. file_exists) then
write(*,*) 'WARNING: File '//trim(&
filename)//' with particle data does not exist.'
write(*,*) 'Initialising particles from user or default routines'
else
open(unit=unitparticles,file=filename,form='unformatted',action='read',&
status='unknown',access='stream')
read(unitparticles) nparticles,it_particles,mynpayload
if (mynpayload .ne. npayload) call &
mpistop&
('npayload in restart file does not match npayload in mod_particles')
end if
end if
call MPI_BCAST(file_exists,1,MPI_LOGICAL,0,icomm,ierrmpi)
if (.not. file_exists) return
call MPI_BCAST(nparticles,1,MPI_INTEGER,0,icomm,ierrmpi)
call MPI_BCAST(it_particles,1,MPI_INTEGER,0,icomm,ierrmpi)
do while (mynparticles .lt. nparticles)
if (mype == 0) then
do while (nparticles_on_mype .lt. nparticles_per_cpu_hi .and. &
mynparticles .lt. nparticles)
call read_from_snapshot
mynparticles = mynparticles + 1
end do
end if ! mype==0
call MPI_BCAST(mynparticles,1,MPI_INTEGER,0,icomm,ierrmpi)
call comm_particles_global
end do
if (mype == 0) close(unit=unitparticles)
end subroutine read_particles_snapshot