| 1 |
!------------------------------------------------------------------------- |
| 2 |
! this subroutine reads from the data file(s) |
| 3 |
! change this to change the format of data input |
| 4 |
! |
| 5 |
! THIS VERSION IS FOR OUTPUT FROM THE GADGET CODE |
| 6 |
! |
| 7 |
! NOTE THAT THIS ONLY "OFFICIALLY" WORKS WITH THE PARALLEL CODE AS WE |
| 8 |
! REQUIRE KNOWLEDGE OF THE PARTICLE SMOOTHING LENGTHS |
| 9 |
! |
| 10 |
! SOME CHOICES FOR THIS FORMAT CAN BE SET USING THE FOLLOWING |
| 11 |
! ENVIRONMENT VARIABLES: |
| 12 |
! |
| 13 |
! GSPLASH_USE_Z if 'YES' uses redshift in the legend instead of time |
| 14 |
! GSPLASH_DARKMATTER_HSOFT if given a value > 0.0 will assign a |
| 15 |
! smoothing length to dark matter particles which can then be |
| 16 |
! used in the rendering |
| 17 |
! |
| 18 |
! the data is stored in the global array dat |
| 19 |
! |
| 20 |
! >> this subroutine must return values for the following: << |
| 21 |
! |
| 22 |
! ncolumns : number of data columns |
| 23 |
! ndim, ndimV : number of spatial, velocity dimensions |
| 24 |
! nstepsread : number of steps read from this file |
| 25 |
! |
| 26 |
! dat(maxpart,maxplot,maxstep) : main data array |
| 27 |
! |
| 28 |
! npartoftype(maxstep): number of particles of each type in each timestep |
| 29 |
! |
| 30 |
! time(maxstep) : time at each step |
| 31 |
! gamma(maxstep) : gamma at each step |
| 32 |
! (used in calc_quantities for calculating the pressure) |
| 33 |
! |
| 34 |
! most of these values are stored in global arrays |
| 35 |
! in the module 'particle_data' |
| 36 |
! |
| 37 |
! Partial data read implemented Nov 2006 means that columns with |
| 38 |
! the 'required' flag set to false are not read (read is therefore much faster) |
| 39 |
!------------------------------------------------------------------------- |
| 40 |
|
| 41 |
module readdata_egaburov |
| 42 |
implicit none |
| 43 |
|
| 44 |
public :: read_data_egaburov, set_labels_egaburov |
| 45 |
|
| 46 |
private |
| 47 |
contains |
| 48 |
|
| 49 |
subroutine read_data_egaburov(rootname,istepstart,ipos,nstepsread) |
| 50 |
use particle_data, only:dat,npartoftype,time,gamma,maxpart,maxcol,maxstep |
| 51 |
use params |
| 52 |
use settings_data, only:ndim,ndimV,ncolumns,ncalc,iformat,required,ipartialread |
| 53 |
use mem_allocation, only:alloc |
| 54 |
use labels, only:ih,irho |
| 55 |
use system_utils, only:renvironment,lenvironment |
| 56 |
integer, intent(in) :: istepstart,ipos |
| 57 |
integer, intent(out) :: nstepsread |
| 58 |
character(len=*), intent(in) :: rootname |
| 59 |
character(len=len(rootname)+10) :: datfile |
| 60 |
integer :: i,j,ierr |
| 61 |
integer :: ncolstep,npart_max,nstep_max |
| 62 |
logical :: iexist,reallocate |
| 63 |
|
| 64 |
|
| 65 |
integer :: proc, nread |
| 66 |
|
| 67 |
integer :: myproc, nproc, npx, npy, npz; |
| 68 |
integer :: global_n, local_n, ndim_data |
| 69 |
real(sing_prec) :: t_global, dt_global |
| 70 |
integer :: iteration |
| 71 |
real(sing_prec) :: cfl_no, gamma_gas |
| 72 |
integer :: periodic_flag |
| 73 |
real(sing_prec) :: xmin, ymin, zmin, xmax, ymax, zmax |
| 74 |
|
| 75 |
integer :: idx |
| 76 |
real(sing_prec) :: posx, posy, posz, pvelx, pvely, pvelz |
| 77 |
real(sing_prec) :: dens, ethm, pres, pmag, vabs |
| 78 |
real(sing_prec) :: velx, vely, velz, Bx, By, Bz |
| 79 |
real(sing_prec) :: hsml, wght, Bpsi, divB, v1, v2, v3, v4 |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
!!!!!!!!!!!!!!!!!! |
| 84 |
|
| 85 |
nstepsread = 0 |
| 86 |
npart_max = maxpart |
| 87 |
|
| 88 |
if (len_trim(rootname) > 0) then |
| 89 |
datfile = trim(rootname) |
| 90 |
else |
| 91 |
print*,' **** no data read **** ' |
| 92 |
return |
| 93 |
endif |
| 94 |
|
| 95 |
! |
| 96 |
!--check if first data file exists |
| 97 |
! |
| 98 |
inquire(file=datfile,exist=iexist) |
| 99 |
if (.not.iexist) then |
| 100 |
print "(a)",' *** error: '//trim(datfile)//': file not found ***' |
| 101 |
stop |
| 102 |
endif |
| 103 |
|
| 104 |
! |
| 105 |
!--set parameters which do not vary between timesteps |
| 106 |
! |
| 107 |
ndim = 3 |
| 108 |
ndimV = 3 |
| 109 |
|
| 110 |
! |
| 111 |
!--read data from snapshots |
| 112 |
! |
| 113 |
i = istepstart |
| 114 |
|
| 115 |
write(*,"(23('-'),1x,a,1x,23('-'))") trim(datfile) |
| 116 |
|
| 117 |
! |
| 118 |
!--open data file and read data |
| 119 |
! |
| 120 |
open(11,iostat=ierr,file=datfile,status='old', form='unformatted') |
| 121 |
if (ierr /= 0) then |
| 122 |
print "(a)", '*** ERROR OPENING FILE ***' |
| 123 |
stop |
| 124 |
endif |
| 125 |
|
| 126 |
! |
| 127 |
!--read header for this timestep |
| 128 |
! |
| 129 |
read(11, iostat=ierr) myproc, nproc, npx, npy, npz, & |
| 130 |
global_n, local_n, ndim_data, t_global, dt_global, iteration, & |
| 131 |
cfl_no, gamma_gas, periodic_flag, & |
| 132 |
xmin, ymin, zmin, xmax, ymax, zmax |
| 133 |
print *, global_n |
| 134 |
print *, local_n |
| 135 |
print *, nproc |
| 136 |
if (ierr /= 0) then |
| 137 |
print "(a)", '*** ERROR READING TIMESTEP HEADER ***' |
| 138 |
stop |
| 139 |
endif |
| 140 |
|
| 141 |
! t_global = t_global - 0.13 |
| 142 |
|
| 143 |
iformat = 0 |
| 144 |
ncolstep = 30 |
| 145 |
ncolumns = ncolstep |
| 146 |
|
| 147 |
print*,'nproc : ',nproc |
| 148 |
print*,'npx, npy, npz : ',npx, npy, npz |
| 149 |
print*,'time : ',t_global |
| 150 |
print*,'gamma_gas : ',gamma_gas |
| 151 |
print*,'N_total : ',global_n |
| 152 |
print*,'N data columns : ',ncolstep |
| 153 |
|
| 154 |
! |
| 155 |
!--if successfully read header, increment the nstepsread counter |
| 156 |
! |
| 157 |
nstepsread = nstepsread + 1 |
| 158 |
|
| 159 |
! |
| 160 |
!--now read data |
| 161 |
! |
| 162 |
reallocate = .false. |
| 163 |
npart_max = maxpart |
| 164 |
nstep_max = max(maxstep,1) |
| 165 |
|
| 166 |
if (global_n > maxpart) then |
| 167 |
reallocate = .true. |
| 168 |
if (maxpart > 0) then |
| 169 |
! if we are reallocating, try not to do it again |
| 170 |
npart_max = int(1.1*global_n) |
| 171 |
else |
| 172 |
! if first time, save on memory |
| 173 |
npart_max = int(global_n) |
| 174 |
endif |
| 175 |
endif |
| 176 |
if (i >= maxstep .and. i /= 1) then |
| 177 |
nstep_max = i + max(10,INT(0.1*nstep_max)) |
| 178 |
reallocate = .true. |
| 179 |
endif |
| 180 |
|
| 181 |
! |
| 182 |
!--reallocate memory for main data array |
| 183 |
! |
| 184 |
if (reallocate .or. .not.(allocated(dat))) then |
| 185 |
call alloc(npart_max,nstep_max,max(ncolstep+ncalc,maxcol)) |
| 186 |
endif |
| 187 |
|
| 188 |
npartoftype(:,i) = 0 |
| 189 |
npartoftype(1,i) = global_n |
| 190 |
|
| 191 |
!--use this line for code time |
| 192 |
time(i) = real(t_global) |
| 193 |
|
| 194 |
! |
| 195 |
!--read particle data |
| 196 |
! |
| 197 |
nread = 0 |
| 198 |
do proc = 1, nproc |
| 199 |
do j = 1, local_n |
| 200 |
read(11, iostat=ierr) & |
| 201 |
idx, & |
| 202 |
posx, posy, posz, pvelx, pvely, pvelz, & |
| 203 |
dens, ethm, pres, pmag, vabs, & |
| 204 |
velx, vely, velz, Bx, By, Bz, & |
| 205 |
hsml, wght, Bpsi, divB, & |
| 206 |
v1, v2, v3, v4 |
| 207 |
! if (pres > 10) then |
| 208 |
! print *, posx, posy, posz |
| 209 |
! endif |
| 210 |
if (ierr /= 0) then |
| 211 |
print *, '*** ERROR READING PARTICLE', i, 'PROC:', myproc |
| 212 |
stop |
| 213 |
endif |
| 214 |
dat(j + nread, 1, i) = posx |
| 215 |
dat(j + nread, 2, i) = posy |
| 216 |
dat(j + nread, 3, i) = posz |
| 217 |
dat(j + nread, 4, i) = velx |
| 218 |
dat(j + nread, 5, i) = vely |
| 219 |
dat(j + nread, 6, i) = velz |
| 220 |
|
| 221 |
dat(j + nread, 7, i) = dens |
| 222 |
dat(j + nread, 8, i) = pres |
| 223 |
dat(j + nread, 9, i) = pmag |
| 224 |
dat(j + nread, 10, i) = vabs |
| 225 |
|
| 226 |
dat(j + nread, 11, i) = Bx |
| 227 |
dat(j + nread, 12, i) = By |
| 228 |
dat(j + nread, 13, i) = Bz |
| 229 |
if (pmag > 0) then |
| 230 |
dat(j + nread, 14, i) = abs(divB/sqrt(pmag*2.0)) |
| 231 |
else |
| 232 |
dat(j + nread, 14, i) = 0.0; |
| 233 |
end if |
| 234 |
|
| 235 |
dat(j + nread, 15, i) = Bpsi |
| 236 |
dat(j + nread, 16, i) = hsml*2 |
| 237 |
dat(j + nread, 17, i) = wght |
| 238 |
|
| 239 |
dat(j + nread, 18, i) = pvelx |
| 240 |
dat(j + nread, 19, i) = pvely |
| 241 |
dat(j + nread, 20, i) = pvelz |
| 242 |
dat(j + nread, 21, i) = abs(divB) |
| 243 |
|
| 244 |
dat(j + nread, 22, i) = dens*wght |
| 245 |
dat(j + nread, 23, i) = pres/dens/(gamma_gas - 1.0) ! uthermal |
| 246 |
dat(j + nread, 24, i) = sqrt(pmag*2.0) |
| 247 |
dat(j + nread, 25, i) = pres + pmag |
| 248 |
dat(j + nread, 26, i) = v1; |
| 249 |
dat(j + nread, 27, i) = v2; |
| 250 |
dat(j + nread, 28, i) = v3; |
| 251 |
dat(j + nread, 29, i) = v4; |
| 252 |
dat(j + nread, 30, i) = idx; |
| 253 |
|
| 254 |
enddo |
| 255 |
nread = nread + local_n; |
| 256 |
|
| 257 |
if (proc < nproc) then |
| 258 |
read(11, iostat=ierr) myproc, nproc, npx, npy, npz, & |
| 259 |
global_n, local_n, ndim_data, t_global, dt_global, iteration, & |
| 260 |
cfl_no, gamma_gas, periodic_flag, & |
| 261 |
xmin, ymin, zmin, xmax, ymax, zmax |
| 262 |
if (ierr /= 0) then |
| 263 |
print *, '*** ERROR READING TIMESTEP HEADER ***, proc=', proc |
| 264 |
stop |
| 265 |
endif |
| 266 |
endif |
| 267 |
enddo |
| 268 |
|
| 269 |
if (nread /= global_n) then |
| 270 |
print *, 'nread= ', nread |
| 271 |
print *, 'global_n= ', global_n |
| 272 |
print "(a)", ' *** SOMETHING WENT WRONG ***' |
| 273 |
stop |
| 274 |
endif |
| 275 |
|
| 276 |
!!!!!!!!!!!!!!!!!!!!! |
| 277 |
gamma = gamma_gas |
| 278 |
|
| 279 |
|
| 280 |
irho = 7 |
| 281 |
ih = 16 |
| 282 |
|
| 283 |
! |
| 284 |
!--set flag to indicate that only part of this file has been read |
| 285 |
! |
| 286 |
if (.not.all(required(1:ncolstep))) ipartialread = .true. |
| 287 |
|
| 288 |
! |
| 289 |
!--close data file and return |
| 290 |
! |
| 291 |
close(unit=11) |
| 292 |
|
| 293 |
if (nstepsread > 0) then |
| 294 |
print*,'>> last step ntot =',sum(npartoftype(:,istepstart+nstepsread-1)) |
| 295 |
endif |
| 296 |
return |
| 297 |
|
| 298 |
end subroutine read_data_egaburov |
| 299 |
|
| 300 |
!!------------------------------------------------------------ |
| 301 |
!! set labels for each column of data |
| 302 |
!!------------------------------------------------------------ |
| 303 |
|
| 304 |
subroutine set_labels_egaburov |
| 305 |
use labels, only:label,iamvec,labelvec,labeltype,ix,ivx,ipmass,ih,irho,ipr,iutherm, idivb, iBfirst |
| 306 |
use params |
| 307 |
use settings_data, only:ndim,ndimV,ncolumns,ntypes,UseTypeInRenderings |
| 308 |
use geometry, only:labelcoord |
| 309 |
use system_utils, only:renvironment |
| 310 |
integer :: i |
| 311 |
|
| 312 |
if (ndim <= 0 .or. ndim > 3) then |
| 313 |
print*,'*** ERROR: ndim = ',ndim,' in set_labels_egaburov ***' |
| 314 |
return |
| 315 |
endif |
| 316 |
if (ndimV <= 0 .or. ndimV > 3) then |
| 317 |
print*,'*** ERROR: ndimV = ',ndimV,' in set_labels_egaburov ***' |
| 318 |
return |
| 319 |
endif |
| 320 |
|
| 321 |
do i=1,ndim |
| 322 |
ix(i) = i |
| 323 |
enddo |
| 324 |
|
| 325 |
ivx = 4 |
| 326 |
irho = 7 |
| 327 |
iutherm = 23 |
| 328 |
ipr = 8 |
| 329 |
ih = 16 |
| 330 |
iBfirst = 11 |
| 331 |
ipmass = 22 |
| 332 |
idivb = 14 |
| 333 |
|
| 334 |
label(ix(1:ndim)) = labelcoord(1:ndim,1) |
| 335 |
label(irho) = 'density' |
| 336 |
label(iutherm) = 'cs' |
| 337 |
label(ih) = 'h' |
| 338 |
label(ipmass) = 'particle mass' |
| 339 |
label(ipr) = 'pressure' |
| 340 |
label(9) = 'Pmag' |
| 341 |
label(10) = 'vabs' |
| 342 |
label(15) = "\gpsi" |
| 343 |
label(18) = 'pvelx' |
| 344 |
label(19) = 'pvely' |
| 345 |
label(20) = 'pvelz' |
| 346 |
label(11) = 'Bx' |
| 347 |
label(12) = 'By' |
| 348 |
label(13) = 'Bz' |
| 349 |
label(14) = 'divB' |
| 350 |
label(24) = '|B|' |
| 351 |
label(25) = 'Ptot' |
| 352 |
label(26) = 'scal0' |
| 353 |
label(27) = 'scal1' |
| 354 |
label(28) = 'scal2' |
| 355 |
label(29) = 'scal3' |
| 356 |
label(30) = 'idx' |
| 357 |
|
| 358 |
|
| 359 |
! |
| 360 |
!--set labels for vector quantities |
| 361 |
! |
| 362 |
iamvec(ivx:ivx+ndimV-1) = ivx |
| 363 |
labelvec(ivx:ivx+ndimV-1) = 'v' |
| 364 |
do i=1,ndimV |
| 365 |
label(ivx+i-1) = trim(labelvec(ivx))//'\d'//labelcoord(i,1) |
| 366 |
enddo |
| 367 |
!--mag field |
| 368 |
if (iBfirst > 0) then |
| 369 |
iamvec(iBfirst:iBfirst+ndimV-1) = iBfirst |
| 370 |
labelvec(iBfirst:iBfirst+ndimV-1) = 'B' |
| 371 |
do i=1,ndimV |
| 372 |
label(iBfirst+i-1) = trim(labelvec(iBfirst))//'\d'//labelcoord(i,1) |
| 373 |
enddo |
| 374 |
endif |
| 375 |
! |
| 376 |
!--set labels for each particle type |
| 377 |
! |
| 378 |
ntypes = 1 |
| 379 |
labeltype(1) = 'gas' |
| 380 |
UseTypeInRenderings(1) = .true. |
| 381 |
|
| 382 |
return |
| 383 |
end subroutine set_labels_egaburov |
| 384 |
end module readdata_egaburov |