Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- !! Reads a mameclot file : Units must have been converted to kpc and Ms before !
- subroutine load_mameclot
- use amr_commons
- use pm_commons
- implicit none
- #ifndef WITHOUTMPI
- include 'mpif.h'
- #endif
- logical :: ok
- integer :: i, ipart
- character (len=128) :: filename
- integer :: nparts, icpu, info
- real(dp) :: tot_mass
- real(dp), dimension(1:1, 1:3) :: xx_dp
- real(dp) :: mm1, xx1, xx2, xx3, vv1, vv2, vv3
- real(dp) :: scale_l, scale_m, scale_d, scale_v, tmp
- integer, dimension(1:nvector)::cc
- integer(i8b),dimension(1:ncpu)::npart_cpu,npart_all
- logical eof
- ! Getting the units for the conversion
- call units(scale_l, tmp, scale_d, scale_v, tmp, tmp)
- ! Mass conversion
- scale_m = scale_d * scale_l**3
- ! Converting boxlen to user units
- write(6,*) 'Mameclot reader. Converting boxlen to user units'
- boxlen = boxlen / scale_l
- write(6,*) 'Boxlen = ', boxlen
- ipart = 0
- if (TRIM(initfile(levelmin)) /= ' ') then
- ! Opening data file
- filename = TRIM(initfile(levelmin))
- inquire(file=filename, exist=ok)
- if (.not. ok) then
- write(*,*) 'No file'//filename
- RETURN
- end if
- eof = .false.
- ! Now we read the data
- open(unit=1, file=filename, action='read', form='formatted')
- ! Distributing particles over processors
- i = 1
- do
- read(1, *, end=100) mm1, xx_dp(1, 1), xx_dp(1, 2), xx_dp(1, 3), vv1, vv2, vv3
- ! Rescaling to user units
- mm1 = mm1 / scale_m
- xx_dp = xx_dp / scale_l
- vv1 = vv1 / scale_v
- vv2 = vv2 / scale_v
- vv3 = vv3 / scale_v
- call cmp_cpumap(xx_dp, cc, 1)
- ! Completely inefficient !
- ! TODO : rework that !
- if (cc(1) == myid) then
- ipart = ipart + 1
- if (ipart .ge. size(mp)) then
- write(*,*) "For ", myid, ipart, " exceeds ", size(mp)
- call clean_stop
- end if
- xp(ipart,1:3) = xx_dp(1,1:3) + boxlen * 0.5
- vp(ipart,1) = vv1
- vp(ipart,2) = vv2
- vp(ipart,3) = vv3
- mp(ipart) = mm1
- levelp(ipart) = levelmin
- idp(ipart) = i
- endif
- i = i + 1
- end do
- 100 continue
- npart = ipart
- if (myid == 1) then
- write(6,*) 'Mameclot reader, ', i-1, 'particles found'
- end if
- npart_cpu=0; npart_all=0
- npart_cpu(myid)=npart
- #ifndef WITHOUTMPI
- #ifndef LONGINT
- call MPI_ALLREDUCE(npart_cpu,npart_all,ncpu,MPI_INTEGER,MPI_SUM,MPI_COMM_RAMSES,info)
- #else
- call MPI_ALLREDUCE(npart_cpu,npart_all,ncpu,MPI_INTEGER8,MPI_SUM,MPI_COMM_RAMSES,info)
- #endif
- npart_cpu(1)=npart_all(1)
- #endif
- do icpu=2,ncpu
- npart_cpu(icpu)=npart_cpu(icpu-1)+npart_all(icpu)
- end do
- write(*,*)'npart=',npart,'/',npartmax
- call flush(6)
- end if
- end subroutine load_mameclot
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement