| 1 |
!----------------------------------------------------------------- |
| 2 |
! |
| 3 |
! This file is (or was) part of SPLASH, a visualisation tool |
| 4 |
! for Smoothed Particle Hydrodynamics written by Daniel Price: |
| 5 |
! |
| 6 |
! http://users.monash.edu.au/~dprice/splash |
| 7 |
! |
| 8 |
! SPLASH comes with ABSOLUTELY NO WARRANTY. |
| 9 |
! This is free software; and you are welcome to redistribute |
| 10 |
! it under the terms of the GNU General Public License |
| 11 |
! (see LICENSE file for details) and the provision that |
| 12 |
! this notice remains intact. If you modify this file, please |
| 13 |
! note section 2a) of the GPLv2 states that: |
| 14 |
! |
| 15 |
! a) You must cause the modified files to carry prominent notices |
| 16 |
! stating that you changed the files and the date of any change. |
| 17 |
! |
| 18 |
! Copyright (C) 2005-2016 Daniel Price. All rights reserved. |
| 19 |
! Contact: [email protected] |
| 20 |
! |
| 21 |
!----------------------------------------------------------------- |
| 22 |
|
| 23 |
!------------------------------------------------------------------------- |
| 24 |
! this subroutine reads from the data file(s) |
| 25 |
! change this to change the format of data input |
| 26 |
! |
| 27 |
! THIS VERSION IS FOR OUTPUT FROM THE GADGET CODE |
| 28 |
! AS MODIFIED BY JAMIE BOLTON |
| 29 |
! |
| 30 |
! the data is stored in the global array dat |
| 31 |
! |
| 32 |
! >> this subroutine must return values for the following: << |
| 33 |
! |
| 34 |
! ncolumns : number of data columns |
| 35 |
! ndim, ndimV : number of spatial, velocity dimensions |
| 36 |
! nstepsread : number of steps read from this file |
| 37 |
! |
| 38 |
! maxplot,maxpart,maxstep : dimensions of main data array |
| 39 |
! dat(maxpart,maxplot,maxstep) : main data array |
| 40 |
! |
| 41 |
! npartoftype(maxstep): number of particles of each type in each timestep |
| 42 |
! |
| 43 |
! time(maxstep) : time at each step |
| 44 |
! gamma(maxstep) : gamma at each step |
| 45 |
! (used in calc_quantities for calculating the pressure) |
| 46 |
! |
| 47 |
! most of these values are stored in global arrays |
| 48 |
! in the module 'particle_data' |
| 49 |
!------------------------------------------------------------------------- |
| 50 |
|
| 51 |
module readdata_gadget_jsb |
| 52 |
implicit none |
| 53 |
|
| 54 |
public :: read_data_gadget_jsb, set_labels_gadget_jsb |
| 55 |
|
| 56 |
private |
| 57 |
contains |
| 58 |
|
| 59 |
subroutine read_data_gadget_jsb(rootname,istart,ipos,nstepsread) |
| 60 |
use particle_data |
| 61 |
use params |
| 62 |
use labels |
| 63 |
use settings_data, only:ndim,ndimV,ncolumns,ncalc |
| 64 |
use mem_allocation |
| 65 |
integer, intent(IN) :: istart,ipos |
| 66 |
integer, intent(OUT) :: nstepsread |
| 67 |
character(LEN=*), intent(IN) :: rootname |
| 68 |
character(LEN=LEN(rootname)+10) :: datfile |
| 69 |
integer, dimension(maxparttypes) :: npartoftypei |
| 70 |
integer, dimension(:), allocatable :: iamtemp |
| 71 |
integer :: i,itype,icol,ifile,idashpos,ierr |
| 72 |
integer :: index1,index2,indexstart,indexend,Nmassesdumped |
| 73 |
integer :: ncol_max,npart_max,nstep_max,ntoti |
| 74 |
logical :: iexist,reallocate |
| 75 |
real(doub_prec) :: timetemp |
| 76 |
real(doub_prec), dimension(6) :: Massoftype |
| 77 |
real, dimension(:), allocatable :: dattemp1 |
| 78 |
real, dimension(:,:), allocatable :: dattemp |
| 79 |
|
| 80 |
nstepsread = 0 |
| 81 |
|
| 82 |
if (len_trim(rootname) > 0) then |
| 83 |
datfile = trim(rootname) |
| 84 |
else |
| 85 |
print*,' **** no data read **** ' |
| 86 |
return |
| 87 |
endif |
| 88 |
! |
| 89 |
!--check if first data file exists |
| 90 |
! |
| 91 |
inquire(file=datfile,exist=iexist) |
| 92 |
if (.not.iexist) then |
| 93 |
print "(a)",' *** error: ',trim(datfile),' file not found ***' |
| 94 |
return |
| 95 |
endif |
| 96 |
! |
| 97 |
!--set parameters which do not vary between timesteps |
| 98 |
! |
| 99 |
ndim = 3 |
| 100 |
ndimV = 3 |
| 101 |
ncol_max = 15 ! 3 x pos, 3 x vel, utherm, rho, Ne, h, pmass |
| 102 |
! |
| 103 |
!--read data from snapshots |
| 104 |
! |
| 105 |
i = istart |
| 106 |
|
| 107 |
print "(1x,a)",'reading Jamie Bolton''s modified GADGET format' |
| 108 |
write(*,"(23('-'),1x,a,1x,23('-'))") trim(datfile) |
| 109 |
! |
| 110 |
!--open data file and read data |
| 111 |
! |
| 112 |
open(11,ERR=81,file=datfile,status='old',form='unformatted') |
| 113 |
! |
| 114 |
!--read header for this timestep |
| 115 |
! |
| 116 |
read(11,ERR=70,end=80) npartoftypei,Massoftype,timetemp |
| 117 |
ntoti = int(sum(npartoftypei)) |
| 118 |
print*,'time : ',timetemp |
| 119 |
print*,'Npart (by type) : ',npartoftypei |
| 120 |
print*,'Mass (by type) : ',Massoftype |
| 121 |
print*,'N_gas : ',npartoftypei(1) |
| 122 |
print*,'N_total : ',ntoti |
| 123 |
|
| 124 |
! |
| 125 |
!--if successfully read header, increment the nstepsread counter |
| 126 |
! |
| 127 |
nstepsread = nstepsread + 1 |
| 128 |
! |
| 129 |
!--now read data |
| 130 |
! |
| 131 |
reallocate = .false. |
| 132 |
npart_max = maxpart |
| 133 |
nstep_max = max(maxstep,1) |
| 134 |
|
| 135 |
if (ntoti > maxpart) then |
| 136 |
reallocate = .true. |
| 137 |
npart_max = int(1.1*ntoti) |
| 138 |
endif |
| 139 |
if (i >= maxstep .and. i /= 1) then |
| 140 |
nstep_max = i + max(10,INT(0.1*nstep_max)) |
| 141 |
reallocate = .true. |
| 142 |
endif |
| 143 |
! |
| 144 |
!--reallocate memory for main data array |
| 145 |
! |
| 146 |
if (reallocate .or. .not.(allocated(dat))) then |
| 147 |
call alloc(npart_max,nstep_max,max(ncol_max+ncalc,maxcol)) |
| 148 |
endif |
| 149 |
! |
| 150 |
!--copy header into header arrays |
| 151 |
! |
| 152 |
npartoftype(:,i) = npartoftypei |
| 153 |
time(i) = real(timetemp) |
| 154 |
|
| 155 |
|
| 156 |
if (ntoti > 0) then |
| 157 |
if (allocated(dattemp)) deallocate(dattemp) |
| 158 |
allocate(dattemp(3,ntoti)) |
| 159 |
! |
| 160 |
!--read positions of all particles |
| 161 |
! |
| 162 |
print*,'positions ',ntoti |
| 163 |
read (11, iostat=ierr) dattemp(1:3,1:ntoti) |
| 164 |
if (ierr /= 0) then |
| 165 |
print "(a)",'error encountered whilst reading positions ' |
| 166 |
return |
| 167 |
else |
| 168 |
do icol=1,3 |
| 169 |
dat(1:ntoti,icol,i) = dattemp(icol,1:ntoti) |
| 170 |
enddo |
| 171 |
endif |
| 172 |
! |
| 173 |
!--same for velocities |
| 174 |
! |
| 175 |
print*,'velocities ',ntoti |
| 176 |
read (11, iostat=ierr) dattemp(1:3,1:ntoti) |
| 177 |
if (ierr /= 0) then |
| 178 |
print "(a)",'error encountered whilst reading velocities' |
| 179 |
else |
| 180 |
do icol=4,6 |
| 181 |
dat(1:ntoti,icol,i) = dattemp(icol-3,1:ntoti) |
| 182 |
enddo |
| 183 |
endif |
| 184 |
! |
| 185 |
!--read particle ID |
| 186 |
! |
| 187 |
print*,'particle ID ',ntoti |
| 188 |
if (allocated(iamtemp)) deallocate(iamtemp) |
| 189 |
allocate(iamtemp(npart_max)) |
| 190 |
read (11, end=66,ERR=73) iamtemp(1:ntoti) |
| 191 |
deallocate(iamtemp) |
| 192 |
! |
| 193 |
!--read particle masses |
| 194 |
! |
| 195 |
!--work out total number of masses dumped |
| 196 |
Nmassesdumped = 0 |
| 197 |
do itype = 1,6 |
| 198 |
if (abs(Massoftype(itype)) < 1.e-8) then |
| 199 |
Nmassesdumped = Nmassesdumped + Npartoftype(itype,i) |
| 200 |
endif |
| 201 |
enddo |
| 202 |
print*,'particle masses ',Nmassesdumped |
| 203 |
|
| 204 |
!--read this number of entries |
| 205 |
if (allocated(dattemp1)) deallocate(dattemp1) |
| 206 |
allocate(dattemp1(Nmassesdumped)) |
| 207 |
if (Nmassesdumped > 0) then |
| 208 |
read(11,end=66,err=74) dattemp1(1:Nmassesdumped) |
| 209 |
endif |
| 210 |
!--now copy to the appropriate sections of the .dat array |
| 211 |
indexstart = 1 |
| 212 |
index1 = 1 |
| 213 |
|
| 214 |
do itype=1,6 |
| 215 |
if (Npartoftype(itype,i) /= 0) then |
| 216 |
index2 = index1 + Npartoftype(itype,i) -1 |
| 217 |
if (abs(Massoftype(itype)) < 1.e-8) then ! masses dumped |
| 218 |
indexend = indexstart + Npartoftype(itype,i) - 1 |
| 219 |
print*,'read ',Npartoftype(itype,i),' masses for type ', & |
| 220 |
itype,index1,'->',index2,indexstart,'->',indexend |
| 221 |
dat(index1:index2,7,i) = dattemp1(indexstart:indexend) |
| 222 |
else ! masses not dumped |
| 223 |
print*,'setting masses for type ',itype,' = ', & |
| 224 |
real(Massoftype(itype)),index1,'->',index2 |
| 225 |
dat(index1:index2,7,i) = real(Massoftype(itype)) |
| 226 |
endif |
| 227 |
index1 = index2 + 1 |
| 228 |
indexstart = indexend + 1 |
| 229 |
endif |
| 230 |
enddo |
| 231 |
deallocate(dattemp1) |
| 232 |
! |
| 233 |
!--read other quantities for rest of particles |
| 234 |
! |
| 235 |
print*,'gas properties ',npartoftype(1,i) |
| 236 |
do icol=8,15 |
| 237 |
!!print*,icol |
| 238 |
read (11, end=66,ERR=78) dat(1:npartoftype(1,i),icol,i) |
| 239 |
! |
| 240 |
!--for some reason the smoothing length output by GADGET is |
| 241 |
! twice the usual SPH smoothing length |
| 242 |
! |
| 243 |
if (icol==15) then |
| 244 |
dat(1:npartoftype(1,i),icol,i) = 0.5*dat(1:npartoftype(1,i),icol,i) |
| 245 |
endif |
| 246 |
enddo |
| 247 |
|
| 248 |
|
| 249 |
else |
| 250 |
ntoti = 1 |
| 251 |
npartoftype(1,i) = 1 |
| 252 |
dat(:,:,i) = 0. |
| 253 |
endif |
| 254 |
|
| 255 |
!!ntot(i-1) = j-1 |
| 256 |
! |
| 257 |
!--now memory has been allocated, set arrays which are constant for all time |
| 258 |
! |
| 259 |
gamma = 5./3. |
| 260 |
goto 68 |
| 261 |
|
| 262 |
66 continue |
| 263 |
print*,'*** end of file reached in ',trim(datfile),' ***' |
| 264 |
! timestep there but data incomplete |
| 265 |
goto 68 |
| 266 |
|
| 267 |
68 continue |
| 268 |
! |
| 269 |
!--close data file and return |
| 270 |
! |
| 271 |
close(unit=11) |
| 272 |
|
| 273 |
ncolumns = ncol_max |
| 274 |
print*,'ncolumns = ',ncolumns |
| 275 |
|
| 276 |
print*,'>> Finished reading: steps =',nstepsread-istart+1, & |
| 277 |
'last step ntot =',sum(npartoftype(:,istart+nstepsread-1)) |
| 278 |
return |
| 279 |
! |
| 280 |
!--errors |
| 281 |
! |
| 282 |
70 continue |
| 283 |
print*,' *** Error encountered while reading timestep header ***' |
| 284 |
print*,' Npartoftype = ',Npartoftype(:,i) |
| 285 |
print*,' Massoftype = ',Massoftype |
| 286 |
return |
| 287 |
|
| 288 |
73 continue |
| 289 |
print*,' *** Error encountered while reading particle ID ***' |
| 290 |
return |
| 291 |
|
| 292 |
74 continue |
| 293 |
print*,' *** Error encountered while reading particle masses ***' |
| 294 |
return |
| 295 |
|
| 296 |
78 continue |
| 297 |
print*,' *** Error encountered while reading gas particle properties ***' |
| 298 |
return |
| 299 |
|
| 300 |
80 continue |
| 301 |
print*,' *** data file empty, no steps read ***' |
| 302 |
return |
| 303 |
|
| 304 |
81 continue |
| 305 |
print*,' *** Error: can''t open data file ***' |
| 306 |
return |
| 307 |
|
| 308 |
end subroutine read_data_gadget_jsb |
| 309 |
|
| 310 |
!!------------------------------------------------------------ |
| 311 |
!! set labels for each column of data |
| 312 |
!!------------------------------------------------------------ |
| 313 |
|
| 314 |
subroutine set_labels_gadget_jsb |
| 315 |
use labels |
| 316 |
use params |
| 317 |
use settings_data |
| 318 |
use geometry, only:labelcoord |
| 319 |
integer :: i |
| 320 |
|
| 321 |
if (ndim <= 0 .or. ndim > 3) then |
| 322 |
print*,'*** ERROR: ndim = ',ndim,' in set_labels_gadget_jsb ***' |
| 323 |
return |
| 324 |
endif |
| 325 |
if (ndimV <= 0 .or. ndimV > 3) then |
| 326 |
print*,'*** ERROR: ndimV = ',ndimV,' in set_labels_gadget_jsb ***' |
| 327 |
return |
| 328 |
endif |
| 329 |
|
| 330 |
do i=1,ndim |
| 331 |
ix(i) = i |
| 332 |
enddo |
| 333 |
ivx = 4 |
| 334 |
ipmass = 7 |
| 335 |
irho = 9 ! location of rho in data array |
| 336 |
ipr = 0 |
| 337 |
iutherm = 8 ! thermal energy |
| 338 |
ih = 15 ! smoothing length |
| 339 |
! |
| 340 |
!--set labels of the quantities read in |
| 341 |
! |
| 342 |
label(ix(1:ndim)) = labelcoord(1:ndim,1) |
| 343 |
label(irho) = '\gr' |
| 344 |
label(iutherm) = 'u' |
| 345 |
label(10) = 'NHp' |
| 346 |
label(11) = 'NHep' |
| 347 |
label(12) = 'NHepp' |
| 348 |
label(13) = 'NH0' |
| 349 |
label(14) = 'NHe0' |
| 350 |
label(ih) = 'h' |
| 351 |
label(ipmass) = 'particle mass' |
| 352 |
! |
| 353 |
!--set labels for vector quantities |
| 354 |
! |
| 355 |
iamvec(ivx:ivx+ndimV-1) = ivx |
| 356 |
labelvec(ivx:ivx+ndimV-1) = 'v' |
| 357 |
do i=1,ndimV |
| 358 |
label(ivx+i-1) = trim(labelvec(ivx))//'\d'//labelcoord(i,1) |
| 359 |
enddo |
| 360 |
|
| 361 |
!--set labels for each particle type |
| 362 |
! |
| 363 |
ntypes = 6 |
| 364 |
labeltype(1) = 'gas' |
| 365 |
labeltype(2) = 'dark matter' |
| 366 |
labeltype(3) = 'boundary 1' |
| 367 |
labeltype(4) = 'boundary 2' |
| 368 |
labeltype(5) = 'star' |
| 369 |
labeltype(6) = 'sink / black hole' |
| 370 |
UseTypeInRenderings(1) = .true. |
| 371 |
UseTypeInRenderings(2:6) = .false. |
| 372 |
|
| 373 |
!----------------------------------------------------------- |
| 374 |
return |
| 375 |
end subroutine set_labels_gadget_jsb |
| 376 |
end module readdata_gadget_jsb |