| 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-2023 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 READING UNFORMATTED OUTPUT FROM |
| 28 |
! THE NEXT GENERATION SPH CODE (sphNG) |
| 29 |
! |
| 30 |
! (also my Phantom SPH code which uses a similar format) |
| 31 |
! |
| 32 |
! *** CONVERTS TO SINGLE PRECISION *** |
| 33 |
! |
| 34 |
! SOME CHOICES FOR THIS FORMAT CAN BE SET USING THE FOLLOWING |
| 35 |
! COMMAND LINE FLAGS: |
| 36 |
! |
| 37 |
! --cm if set, then centre of mass is reset to origin |
| 38 |
! --omega=3.142 if non-zero subtracts corotating velocities with omega as set |
| 39 |
! --omegat=3.142 if non-zero subtracts corotating positions and velocities with omega as set |
| 40 |
! --timeunits='yrs' sets default time units, either 's','min','hrs','yrs' or 'tfreefall' |
| 41 |
! |
| 42 |
! the data is stored in the global array dat |
| 43 |
! |
| 44 |
! >> this subroutine must return values for the following: << |
| 45 |
! |
| 46 |
! ncolumns : number of data columns |
| 47 |
! ndim, ndimV : number of spatial, velocity dimensions |
| 48 |
! nstepsread : number of steps read from this file |
| 49 |
! |
| 50 |
! maxplot,maxpart,maxstep : dimensions of main data array |
| 51 |
! dat(maxplot,maxpart,maxstep) : main data array |
| 52 |
! |
| 53 |
! npartoftype(1:6,maxstep) : number of particles of each type in each timestep |
| 54 |
! |
| 55 |
! time(maxstep) : time at each step |
| 56 |
! gamma(maxstep) : gamma at each step |
| 57 |
! |
| 58 |
! most of these values are stored in global arrays |
| 59 |
! in the module 'particle_data' |
| 60 |
! |
| 61 |
! Partial data read implemented Nov 2006 means that columns with |
| 62 |
! the 'required' flag set to false are not read (read is therefore much faster) |
| 63 |
!------------------------------------------------------------------------- |
| 64 |
module sphNGread |
| 65 |
use params |
| 66 |
implicit none |
| 67 |
real(doub_prec) :: udist,umass,utime,umagfd |
| 68 |
real :: tfreefall,dtmax |
| 69 |
integer :: istartmhd,istartrt,nmhd,idivvcol,idivvxcol,icurlvxcol,icurlvycol,icurlvzcol,iHIIcol,iHeIIcol,iHeIIIcol |
| 70 |
integer :: nhydroreal4,istart_extra_real4 |
| 71 |
integer :: itempcol = 0 |
| 72 |
integer :: ncolstepfirst = 0 |
| 73 |
integer :: nhydroarrays,nmhdarrays,ndustarrays,ndustlarge |
| 74 |
logical :: phantomdump,smalldump,mhddump,rtdump,usingvecp,igotmass,h2chem,rt_in_header |
| 75 |
logical :: usingeulr,cleaning |
| 76 |
logical :: batcode,tagged,debug |
| 77 |
integer, parameter :: maxarrsizes = 10 |
| 78 |
integer, parameter :: maxinblock = 128 ! max allowed in each block |
| 79 |
integer, parameter :: lentag = 16 |
| 80 |
character(len=lentag) :: tagarr(maxplot) |
| 81 |
integer, parameter :: itypemap_sink_phantom = 3 |
| 82 |
integer, parameter :: itypemap_dust_phantom = 2 |
| 83 |
integer, parameter :: itypemap_unknown_phantom = maxparttypes |
| 84 |
real, allocatable :: grainsize(:) |
| 85 |
|
| 86 |
!------------------------------------------ |
| 87 |
! generic interface to utilities for tagged |
| 88 |
! dump format |
| 89 |
!------------------------------------------ |
| 90 |
interface extract |
| 91 |
module procedure extract_int, extract_real4, extract_real8, & |
| 92 |
extract_intarr, extract_real4arr, extract_real8arr |
| 93 |
end interface extract |
| 94 |
|
| 95 |
contains |
| 96 |
|
| 97 |
!------------------------------------------------------------------- |
| 98 |
! function mapping iphase setting in sphNG to splash particle types |
| 99 |
!------------------------------------------------------------------- |
| 100 |
elemental integer function itypemap_sphNG(iphase) |
| 101 |
integer*1, intent(in) :: iphase |
| 102 |
|
| 103 |
select case(int(iphase)) |
| 104 |
case(0) |
| 105 |
itypemap_sphNG = 1 ! gas |
| 106 |
case(11:) |
| 107 |
itypemap_sphNG = 2 ! dust |
| 108 |
case(1:9) |
| 109 |
itypemap_sphNG = 4 ! nptmass |
| 110 |
case(10) |
| 111 |
itypemap_sphNG = 5 ! star |
| 112 |
case default |
| 113 |
itypemap_sphNG = 6 ! unknown |
| 114 |
end select |
| 115 |
|
| 116 |
end function itypemap_sphNG |
| 117 |
|
| 118 |
!--------------------------------------------------------------------- |
| 119 |
! function mapping iphase setting in Phantom to splash particle types |
| 120 |
!--------------------------------------------------------------------- |
| 121 |
elemental integer function itypemap_phantom(iphase) |
| 122 |
integer*1, intent(in) :: iphase |
| 123 |
|
| 124 |
select case(int(iphase)) |
| 125 |
case(1:2) |
| 126 |
itypemap_phantom = iphase |
| 127 |
case(3:itypemap_unknown_phantom-1) ! put sinks as type 3, everything else shifted by one |
| 128 |
itypemap_phantom = iphase + 1 |
| 129 |
case(-3) ! sink particles, either from external_binary or read from dump |
| 130 |
itypemap_phantom = itypemap_sink_phantom |
| 131 |
case default |
| 132 |
itypemap_phantom = itypemap_unknown_phantom |
| 133 |
end select |
| 134 |
|
| 135 |
end function itypemap_phantom |
| 136 |
|
| 137 |
!------------------------------------------ |
| 138 |
! extraction of single integer variables |
| 139 |
!------------------------------------------ |
| 140 |
subroutine extract_int(tag,ival,intarr,tags,ntags,ierr,verbose) |
| 141 |
character(len=*), intent(in) :: tag |
| 142 |
integer, intent(out) :: ival |
| 143 |
integer, intent(in) :: ntags,intarr(:) |
| 144 |
character(len=lentag), intent(in) :: tags(:) |
| 145 |
integer, intent(out) :: ierr |
| 146 |
logical, intent(in), optional :: verbose |
| 147 |
logical :: matched |
| 148 |
integer :: i |
| 149 |
|
| 150 |
ierr = 1 |
| 151 |
matched = .false. |
| 152 |
ival = 0 ! default if not found |
| 153 |
over_tags: do i=1,min(ntags,size(tags)) |
| 154 |
if (trim(tags(i))==trim(adjustl(tag))) then |
| 155 |
if (size(intarr) >= i) then |
| 156 |
ival = intarr(i) |
| 157 |
matched = .true. |
| 158 |
endif |
| 159 |
exit over_tags ! only match first occurrence |
| 160 |
endif |
| 161 |
enddo over_tags |
| 162 |
if (matched) ierr = 0 |
| 163 |
if (ierr /= 0 .and. .not.present(verbose)) & |
| 164 |
print "(a)",' WARNING: could not find '//trim(adjustl(tag))//' in header' |
| 165 |
|
| 166 |
end subroutine extract_int |
| 167 |
|
| 168 |
!------------------------------------------ |
| 169 |
! extraction of single real*8 variables |
| 170 |
!------------------------------------------ |
| 171 |
subroutine extract_real8(tag,rval,r8arr,tags,ntags,ierr) |
| 172 |
character(len=*), intent(in) :: tag |
| 173 |
real*8, intent(out) :: rval |
| 174 |
real*8, intent(in) :: r8arr(:) |
| 175 |
character(len=lentag), intent(in) :: tags(:) |
| 176 |
integer, intent(in) :: ntags |
| 177 |
integer, intent(out) :: ierr |
| 178 |
logical :: matched |
| 179 |
integer :: i |
| 180 |
|
| 181 |
ierr = 1 |
| 182 |
matched = .false. |
| 183 |
rval = 0.d0 ! default if not found |
| 184 |
over_tags: do i=1,min(ntags,size(tags)) |
| 185 |
if (trim(tags(i))==trim(adjustl(tag))) then |
| 186 |
if (size(r8arr) >= i) then |
| 187 |
rval = r8arr(i) |
| 188 |
matched = .true. |
| 189 |
endif |
| 190 |
exit over_tags ! only match first occurrence |
| 191 |
endif |
| 192 |
enddo over_tags |
| 193 |
if (matched) ierr = 0 |
| 194 |
if (ierr /= 0) print "(a)",' WARNING: could not find '//trim(adjustl(tag))//' in header' |
| 195 |
|
| 196 |
end subroutine extract_real8 |
| 197 |
|
| 198 |
!------------------------------------------ |
| 199 |
! extraction of single real*4 variables |
| 200 |
!------------------------------------------ |
| 201 |
subroutine extract_real4(tag,rval,r4arr,tags,ntags,ierr) |
| 202 |
character(len=*), intent(in) :: tag |
| 203 |
real*4, intent(out) :: rval |
| 204 |
real*4, intent(in) :: r4arr(:) |
| 205 |
character(len=lentag), intent(in) :: tags(:) |
| 206 |
integer, intent(in) :: ntags |
| 207 |
integer, intent(out) :: ierr |
| 208 |
logical :: matched |
| 209 |
integer :: i |
| 210 |
|
| 211 |
ierr = 1 |
| 212 |
matched = .false. |
| 213 |
rval = 0. ! default if not found |
| 214 |
over_tags: do i=1,min(ntags,size(tags)) |
| 215 |
if (trim(tags(i))==trim(adjustl(tag))) then |
| 216 |
if (size(r4arr) >= i) then |
| 217 |
rval = r4arr(i) |
| 218 |
matched = .true. |
| 219 |
endif |
| 220 |
exit over_tags ! only match first occurrence |
| 221 |
endif |
| 222 |
enddo over_tags |
| 223 |
if (matched) ierr = 0 |
| 224 |
if (ierr /= 0) print "(a)",' WARNING: could not find '//trim(adjustl(tag))//' in header' |
| 225 |
|
| 226 |
end subroutine extract_real4 |
| 227 |
|
| 228 |
!------------------------------------------ |
| 229 |
! extraction of integer arrays |
| 230 |
!------------------------------------------ |
| 231 |
subroutine extract_intarr(tag,ival,intarr,tags,ntags,ierr) |
| 232 |
character(len=*), intent(in) :: tag |
| 233 |
integer, intent(out) :: ival(:) |
| 234 |
integer, intent(in) :: ntags,intarr(:) |
| 235 |
character(len=lentag), intent(in) :: tags(:) |
| 236 |
integer, intent(out) :: ierr |
| 237 |
integer :: i,nmatched |
| 238 |
|
| 239 |
ierr = 1 |
| 240 |
nmatched = 0 |
| 241 |
ival(:) = 0 ! default if not found |
| 242 |
over_tags: do i=1,min(ntags,size(tags)) |
| 243 |
if (trim(tags(i))==trim(adjustl(tag))) then |
| 244 |
if (size(intarr) >= i .and. size(ival) > nmatched) then |
| 245 |
nmatched = nmatched + 1 |
| 246 |
ival(nmatched) = intarr(i) |
| 247 |
endif |
| 248 |
endif |
| 249 |
enddo over_tags |
| 250 |
if (nmatched==size(ival)) ierr = 0 |
| 251 |
if (ierr /= 0) print "(a)",' WARNING: could not find '//trim(adjustl(tag))//' in header' |
| 252 |
|
| 253 |
end subroutine extract_intarr |
| 254 |
|
| 255 |
!------------------------------------------ |
| 256 |
! extraction of real*8 arrays |
| 257 |
!------------------------------------------ |
| 258 |
subroutine extract_real8arr(tag,rval,r8arr,tags,ntags,ierr) |
| 259 |
character(len=*), intent(in) :: tag |
| 260 |
real*8, intent(out) :: rval(:) |
| 261 |
real*8, intent(in) :: r8arr(:) |
| 262 |
character(len=lentag), intent(in) :: tags(:) |
| 263 |
integer, intent(in) :: ntags |
| 264 |
integer, intent(out) :: ierr |
| 265 |
integer :: i,nmatched |
| 266 |
|
| 267 |
ierr = 1 |
| 268 |
nmatched = 0 |
| 269 |
rval = 0.d0 ! default if not found |
| 270 |
over_tags: do i=1,min(ntags,size(tags)) |
| 271 |
if (trim(tags(i))==trim(adjustl(tag))) then |
| 272 |
if (size(r8arr) >= i .and. size(rval) > nmatched) then |
| 273 |
nmatched = nmatched + 1 |
| 274 |
rval(nmatched) = r8arr(i) |
| 275 |
endif |
| 276 |
endif |
| 277 |
enddo over_tags |
| 278 |
if (nmatched==size(rval)) ierr = 0 |
| 279 |
if (ierr /= 0) print "(a)",' WARNING: could not find '//trim(adjustl(tag))//' in header' |
| 280 |
|
| 281 |
end subroutine extract_real8arr |
| 282 |
|
| 283 |
!------------------------------------------ |
| 284 |
! extraction of real*4 arrays |
| 285 |
!------------------------------------------ |
| 286 |
subroutine extract_real4arr(tag,rval,r4arr,tags,ntags,ierr) |
| 287 |
character(len=*), intent(in) :: tag |
| 288 |
real*4, intent(out) :: rval(:) |
| 289 |
real*4, intent(in) :: r4arr(:) |
| 290 |
character(len=lentag), intent(in) :: tags(:) |
| 291 |
integer, intent(in) :: ntags |
| 292 |
integer, intent(out) :: ierr |
| 293 |
integer :: i,nmatched |
| 294 |
|
| 295 |
ierr = 1 |
| 296 |
nmatched = 0 |
| 297 |
rval = 0. ! default if not found |
| 298 |
over_tags: do i=1,min(ntags,size(tags)) |
| 299 |
if (trim(tags(i))==trim(adjustl(tag))) then |
| 300 |
if (size(r4arr) >= i .and. size(rval) > nmatched) then |
| 301 |
nmatched = nmatched + 1 |
| 302 |
rval(nmatched) = r4arr(i) |
| 303 |
endif |
| 304 |
endif |
| 305 |
enddo over_tags |
| 306 |
if (nmatched==size(rval)) ierr = 0 |
| 307 |
if (ierr /= 0) print "(a)",' WARNING: could not find '//trim(adjustl(tag))//' in header' |
| 308 |
|
| 309 |
end subroutine extract_real4arr |
| 310 |
|
| 311 |
!---------------------------------------------------------------------- |
| 312 |
! Extract various options from the fileident string |
| 313 |
!---------------------------------------------------------------------- |
| 314 |
subroutine get_options_from_fileident(fileident,smalldump,tagged,phantomdump,& |
| 315 |
usingvecp,usingeulr,cleaning,h2chem,rt_in_header,batcode) |
| 316 |
character(len=*), intent(in) :: fileident |
| 317 |
logical, intent(out) :: smalldump,tagged,phantomdump,batcode |
| 318 |
logical, intent(out) :: usingvecp,usingeulr,cleaning,h2chem,rt_in_header |
| 319 |
|
| 320 |
smalldump = .false. |
| 321 |
phantomdump = .false. |
| 322 |
usingvecp = .false. |
| 323 |
usingeulr = .false. |
| 324 |
cleaning = .false. |
| 325 |
h2chem = .false. |
| 326 |
rt_in_header = .false. |
| 327 |
batcode = .false. |
| 328 |
tagged = .false. |
| 329 |
if (fileident(1:1)=='S') then |
| 330 |
smalldump = .true. |
| 331 |
endif |
| 332 |
if (fileident(2:2)=='T') then |
| 333 |
tagged = .true. |
| 334 |
endif |
| 335 |
if (index(fileident,'Phantom') /= 0) then |
| 336 |
phantomdump = .true. |
| 337 |
else |
| 338 |
phantomdump = .false. |
| 339 |
endif |
| 340 |
if (index(fileident,'vecp') /= 0) then |
| 341 |
usingvecp = .true. |
| 342 |
endif |
| 343 |
if (index(fileident,'eulr') /= 0) then |
| 344 |
usingeulr = .true. |
| 345 |
endif |
| 346 |
if (index(fileident,'clean') /= 0) then |
| 347 |
cleaning = .true. |
| 348 |
endif |
| 349 |
if (index(fileident,'H2chem') /= 0) then |
| 350 |
h2chem = .true. |
| 351 |
endif |
| 352 |
if (index(fileident,'RT=on') /= 0) then |
| 353 |
rt_in_header = .true. |
| 354 |
endif |
| 355 |
if (index(fileident,'This is a test') /= 0) then |
| 356 |
batcode = .true. |
| 357 |
endif |
| 358 |
|
| 359 |
end subroutine get_options_from_fileident |
| 360 |
|
| 361 |
!---------------------------------------------------------------------- |
| 362 |
! Set position of header items manually for older (untagged) formats |
| 363 |
!---------------------------------------------------------------------- |
| 364 |
subroutine fake_header_tags(nreals,realarr,tagsreal) |
| 365 |
integer, intent(in) :: nreals |
| 366 |
real, intent(in) :: realarr(nreals) |
| 367 |
character(len=*), intent(out) :: tagsreal(:) |
| 368 |
integer, parameter :: ilocbinary = 24 |
| 369 |
integer :: ipos |
| 370 |
! |
| 371 |
!--set the tags manually for older formats |
| 372 |
! (but only the ones we care about) |
| 373 |
! |
| 374 |
if (phantomdump) then |
| 375 |
tagsreal(1) = 'time' |
| 376 |
tagsreal(3) = 'gamma' |
| 377 |
tagsreal(4) = 'rhozero' |
| 378 |
tagsreal(6) = 'hfact' |
| 379 |
tagsreal(7) = 'tolh' |
| 380 |
tagsreal(15:19) = 'massoftype' |
| 381 |
if (nreals >= ilocbinary + 14) then |
| 382 |
if (nreals >= ilocbinary + 15) then |
| 383 |
ipos = ilocbinary |
| 384 |
else |
| 385 |
print*,'*** WARNING: obsolete header format for external binary information ***' |
| 386 |
ipos = ilocbinary + 1 |
| 387 |
endif |
| 388 |
if (debug) print*,'DEBUG: reading binary information from header ',ilocbinary |
| 389 |
if (any(realarr(ilocbinary:ilocbinary+14) /= 0.)) then |
| 390 |
tagsreal(ipos:ipos+2) = (/'x1','y1','z1'/) |
| 391 |
if (nreals >= ilocbinary+15) then |
| 392 |
tagsreal(ipos+3:ipos+9) = (/'m1','h1','x2','y2','z2','m2','h2'/) |
| 393 |
ipos = ipos + 10 |
| 394 |
else |
| 395 |
tagsreal(ipos+3:ipos+7) = (/'h1','x2','y2','z2','h2'/) |
| 396 |
ipos = ipos + 8 |
| 397 |
endif |
| 398 |
tagsreal(ipos:ipos+5) = (/'vx1','vy1','vz1','vx2','vy2','vz2'/) |
| 399 |
endif |
| 400 |
endif |
| 401 |
elseif (batcode) then |
| 402 |
tagsreal(1) = 'time' |
| 403 |
tagsreal(3) = 'gamma' |
| 404 |
tagsreal(4) = 'radL1' |
| 405 |
tagsreal(5) = 'PhiL1' |
| 406 |
tagsreal(15) = 'Er' |
| 407 |
else |
| 408 |
tagsreal(1) = 'gt' |
| 409 |
tagsreal(2) = 'dtmax' |
| 410 |
tagsreal(3) = 'gamma' |
| 411 |
tagsreal(4) = 'rhozero' |
| 412 |
tagsreal(5) = 'RK2' |
| 413 |
if (smalldump) then ! sphNG small dump |
| 414 |
if (nreals==15) then |
| 415 |
tagsreal(15) = 'pmassinitial' |
| 416 |
else |
| 417 |
tagsreal(23) = 'pmassinitial' |
| 418 |
endif |
| 419 |
endif |
| 420 |
endif |
| 421 |
|
| 422 |
end subroutine fake_header_tags |
| 423 |
|
| 424 |
subroutine set_grain_sizes(ntags,tags,vals,udist) |
| 425 |
integer, intent(in) :: ntags |
| 426 |
character(len=*), intent(in) :: tags(ntags) |
| 427 |
real, intent(inout) :: vals(ntags) |
| 428 |
real(doub_prec), intent(in) :: udist |
| 429 |
integer :: i,nd |
| 430 |
|
| 431 |
! convert grain sizes to cm |
| 432 |
nd = 0 |
| 433 |
do i=1,ntags |
| 434 |
if (index(tags(i),'grainsize') > 0) then |
| 435 |
nd = nd + 1 |
| 436 |
vals(i) = vals(i)*udist |
| 437 |
endif |
| 438 |
enddo |
| 439 |
|
| 440 |
if (allocated(grainsize)) deallocate(grainsize) |
| 441 |
allocate(grainsize(nd)) |
| 442 |
|
| 443 |
nd = 0 |
| 444 |
do i=1,ntags |
| 445 |
if (index(tags(i),'grainsize') > 0) then |
| 446 |
nd = nd + 1 |
| 447 |
grainsize(nd) = vals(i) |
| 448 |
endif |
| 449 |
enddo |
| 450 |
|
| 451 |
end subroutine set_grain_sizes |
| 452 |
|
| 453 |
!---------------------------------------------------------------------- |
| 454 |
! print information about dust grain sizes found in header |
| 455 |
!---------------------------------------------------------------------- |
| 456 |
subroutine print_dustgrid_info(ntags,tags,vals,mgas) |
| 457 |
use asciiutils, only:match_tag |
| 458 |
use labels, only:get_label_grain_size |
| 459 |
integer, intent(in) :: ntags |
| 460 |
character(len=*), intent(in) :: tags(ntags) |
| 461 |
real, intent(in) :: vals(ntags),mgas |
| 462 |
integer :: i,nd |
| 463 |
|
| 464 |
nd = 0 |
| 465 |
if (match_tag(tags,'grainsize1') > 0) then |
| 466 |
print "(/,a)",' Dust grid:' |
| 467 |
do i=1,ntags |
| 468 |
if (index(tags(i),'grainsize') > 0 .and. vals(i) > 0.) then |
| 469 |
nd = nd + 1 |
| 470 |
print "(i3,a)",nd,': '//get_label_grain_size(vals(i)) |
| 471 |
endif |
| 472 |
enddo |
| 473 |
if (nd > 0) print "(a)" |
| 474 |
endif |
| 475 |
|
| 476 |
! nd = 0 |
| 477 |
! print *,' mgas = ',mgas/(2d33/umass) |
| 478 |
! do i=1,ntags |
| 479 |
! if (index(tags(i),'mdust_in') > 0) then |
| 480 |
! nd = nd + 1 |
| 481 |
! if (vals(i) > 0.) print "(i3,a,1pg10.3,a,1pg10.3)",nd,': mass = ',vals(i)/(2d33/umass),& |
| 482 |
! ' Msun; d/g = ',vals(i)/mgas |
| 483 |
! endif |
| 484 |
! enddo |
| 485 |
|
| 486 |
end subroutine print_dustgrid_info |
| 487 |
|
| 488 |
!---------------------------------------------------------------------- |
| 489 |
! Routine to read the header of sphNG dump files and extract relevant |
| 490 |
! information |
| 491 |
!---------------------------------------------------------------------- |
| 492 |
subroutine read_header(iunit,iverbose,debug,doubleprec,& |
| 493 |
npart,npartoftypei,n1,ntypes,nblocks,& |
| 494 |
narrsizes,realarr,tagsreal,nreals,ierr) |
| 495 |
use settings_data, only:ndusttypes |
| 496 |
integer, intent(in) :: iunit,iverbose |
| 497 |
logical, intent(in) :: debug,doubleprec |
| 498 |
integer, intent(out) :: npart,npartoftypei(:),n1,ntypes,nblocks,narrsizes,nreals,ierr |
| 499 |
real, intent(out) :: realarr(maxinblock) |
| 500 |
character(len=lentag), intent(out) :: tagsreal(maxinblock) |
| 501 |
character(len=lentag) :: tags(maxinblock) |
| 502 |
integer :: intarr(maxinblock) |
| 503 |
real(doub_prec) :: real8arr(maxinblock) |
| 504 |
real(sing_prec) :: real4arr(maxinblock) |
| 505 |
integer :: i,ierr1,ierr2,ierrs(4) |
| 506 |
integer :: nints,ninttypes,nreal4s,nreal8s |
| 507 |
integer :: n2,nreassign,naccrete,nkill |
| 508 |
integer, allocatable :: npartoftype_tmp(:) |
| 509 |
|
| 510 |
! initialise empty tag array |
| 511 |
tags(:) = '' |
| 512 |
intarr(:) = 0 |
| 513 |
|
| 514 |
nblocks = 1 ! number of MPI blocks |
| 515 |
npartoftypei(:) = 0 |
| 516 |
read(iunit,iostat=ierr) nints |
| 517 |
if (ierr /=0) then |
| 518 |
print "(a)",'error reading nints' |
| 519 |
return |
| 520 |
else |
| 521 |
if (tagged) then |
| 522 |
if (nints > maxinblock) then |
| 523 |
if (iverbose > 0) print*,'WARNING: number of ints in header exceeds splash array limit, ignoring some' |
| 524 |
nints = maxinblock |
| 525 |
endif |
| 526 |
read(iunit,iostat=ierr1) tags(1:nints) |
| 527 |
read(iunit,iostat=ierr2) intarr(1:nints) |
| 528 |
if (ierr1 /= 0 .or. ierr2 /= 0) then |
| 529 |
print "(a)",'error reading integer header' |
| 530 |
ierr = 1 |
| 531 |
return |
| 532 |
endif |
| 533 |
if (debug) print*,'DEBUG: got tags = ',tags(1:nints) |
| 534 |
call extract('nblocks',nblocks,intarr,tags,nints,ierr) |
| 535 |
if (ierr /= 0) return |
| 536 |
call extract('nparttot',npart,intarr,tags,nints,ierr) |
| 537 |
if (ierr /= 0) return |
| 538 |
if (phantomdump) then |
| 539 |
call extract('ntypes',ntypes,intarr,tags,nints,ierr) |
| 540 |
if (ierr /= 0) return |
| 541 |
|
| 542 |
allocate(npartoftype_tmp(ntypes)) |
| 543 |
call extract('npartoftype',npartoftype_tmp(1:ntypes),intarr,tags,nints,ierr) |
| 544 |
if (ntypes > maxparttypes) then |
| 545 |
if (iverbose > 0 .and. any(npartoftype_tmp(maxparttypes+1:) > 0)) & |
| 546 |
print "(a,i2)",' WARNING: number of particle types exceeds array limits: ignoring types > ',maxparttypes |
| 547 |
ntypes = maxparttypes |
| 548 |
endif |
| 549 |
npartoftypei(1:ntypes) = npartoftype_tmp(1:ntypes) |
| 550 |
if (ierr /= 0) return |
| 551 |
endif |
| 552 |
if (phantomdump .and. nints < 7) ntypes = nints - 1 |
| 553 |
if (iverbose >= 2 .or. debug) print *,'npart = ',npart,' MPI blocks = ',nblocks |
| 554 |
if (phantomdump) then |
| 555 |
n1 = npartoftypei(1) |
| 556 |
else |
| 557 |
call extract('n1',n1,intarr,tags,nints,ierr) |
| 558 |
endif |
| 559 |
else |
| 560 |
if (nints < 3) then |
| 561 |
if (.not.phantomdump) print "(a)",'WARNING: npart,n1,n2 NOT IN HEADER??' |
| 562 |
read(iunit,iostat=ierr) npart |
| 563 |
npartoftypei(1) = npart |
| 564 |
elseif (phantomdump) then |
| 565 |
if (nints < 7) then |
| 566 |
ntypes = nints - 1 |
| 567 |
read(iunit,iostat=ierr) npart,npartoftypei(1:ntypes) |
| 568 |
else |
| 569 |
ntypes = 5 |
| 570 |
read(iunit,iostat=ierr) npart,npartoftypei(1:5),nblocks |
| 571 |
endif |
| 572 |
if (debug) then |
| 573 |
print*,'DEBUG: ntypes = ',ntypes,' npartoftype = ',npartoftypei(:) |
| 574 |
endif |
| 575 |
n1 = npartoftypei(1) |
| 576 |
n2 = 0 |
| 577 |
elseif (nints >= 7) then |
| 578 |
read(iunit,iostat=ierr) npart,n1,n2,nreassign,naccrete,nkill,nblocks |
| 579 |
else |
| 580 |
print "(a)",'warning: nblocks not read from file (assuming non-MPI dump)' |
| 581 |
read(iunit,iostat=ierr) npart,n1,n2 |
| 582 |
endif |
| 583 |
if (ierr /=0) then |
| 584 |
print "(a)",'error reading npart,n1,n2 and/or number of MPI blocks' |
| 585 |
return |
| 586 |
elseif (nblocks > 2000) then |
| 587 |
print *,'npart = ',npart,' MPI blocks = ',nblocks |
| 588 |
nblocks = 1 |
| 589 |
print*,' corrupt number of MPI blocks, assuming 1 ' |
| 590 |
else |
| 591 |
if (iverbose >= 1) print *,'npart = ',npart,' MPI blocks = ',nblocks |
| 592 |
endif |
| 593 |
endif |
| 594 |
endif |
| 595 |
|
| 596 |
!--int*1, int*2, int*4, int*8 |
| 597 |
ierr1 = 0 |
| 598 |
ierr2 = 0 |
| 599 |
do i=1,4 |
| 600 |
read(iunit,iostat=ierr) ninttypes |
| 601 |
if (ninttypes > 0) then |
| 602 |
if (tagged) read(iunit,iostat=ierr1) |
| 603 |
read(iunit,iostat=ierr2) |
| 604 |
endif |
| 605 |
if (ierr /= 0 .or. ierr1 /= 0 .or. ierr2 /= 0) then |
| 606 |
print "(a)",'error skipping int types' |
| 607 |
return |
| 608 |
endif |
| 609 |
enddo |
| 610 |
!--default reals |
| 611 |
read(iunit,iostat=ierr) nreals |
| 612 |
if (ierr /=0) then |
| 613 |
print "(a)",'error reading default reals' |
| 614 |
return |
| 615 |
else |
| 616 |
if (nreals > maxinblock) then |
| 617 |
print*,'WARNING: number of reals in header exceeds splash array limit, ignoring some' |
| 618 |
nreals = maxinblock |
| 619 |
endif |
| 620 |
if (tagged) read(iunit,iostat=ierr) tagsreal(1:nreals) |
| 621 |
if (doubleprec) then |
| 622 |
read(iunit,iostat=ierr) real8arr(1:nreals) |
| 623 |
realarr(1:nreals) = real(real8arr(1:nreals)) |
| 624 |
else |
| 625 |
read(iunit,iostat=ierr) real4arr(1:nreals) |
| 626 |
realarr(1:nreals) = real(real4arr(1:nreals)) |
| 627 |
endif |
| 628 |
if (.not.tagged) call fake_header_tags(nreals,realarr,tagsreal) |
| 629 |
endif |
| 630 |
! |
| 631 |
!--append integers to realarr so they can be used in |
| 632 |
! legends and calculated quantities |
| 633 |
! |
| 634 |
if (nreals+nints <= maxinblock) then |
| 635 |
tagsreal(nreals+1:nreals+nints) = tags(1:nints) |
| 636 |
realarr(nreals+1:nreals+nints) = real(intarr(1:nints)) |
| 637 |
nreals = nreals + nints |
| 638 |
endif |
| 639 |
|
| 640 |
!--real*4, real*8 |
| 641 |
read(iunit,iostat=ierr) nreal4s |
| 642 |
if (nreal4s > 0) then |
| 643 |
if (tagged) read(iunit,iostat=ierr1) |
| 644 |
read(iunit,iostat=ierr2) |
| 645 |
endif |
| 646 |
if (ierr /= 0 .or. ierr1 /= 0 .or. ierr2 /= 0) then |
| 647 |
print "(a)",'error skipping real*4''s in header' |
| 648 |
return |
| 649 |
endif |
| 650 |
|
| 651 |
read(iunit,iostat=ierr) nreal8s |
| 652 |
if (ierr /= 0 .or. nreal8s < 0) then |
| 653 |
print "(a)",'error reading nreal8s' |
| 654 |
return |
| 655 |
endif |
| 656 |
! print "(a,i3)",' ndoubles = ',nreal8s |
| 657 |
if (iverbose >= 2 .or. debug) print "(4(a,i3),a)",' header contains ',nints,' ints, ',& |
| 658 |
nreals,' reals,',nreal4s,' real4s, ',nreal8s,' doubles' |
| 659 |
if (tagged) then |
| 660 |
if (nreal8s > maxinblock) then |
| 661 |
print*,'WARNING: number of real8''s in header exceeds splash array limit, ignoring some' |
| 662 |
nreal8s = maxinblock |
| 663 |
endif |
| 664 |
read(iunit,iostat=ierr) tags(1:nreal8s) |
| 665 |
read(iunit,iostat=ierr) real8arr(1:nreal8s) |
| 666 |
call extract('udist',udist,real8arr,tags,nreal8s,ierrs(1)) |
| 667 |
call extract('umass',umass,real8arr,tags,nreal8s,ierrs(2)) |
| 668 |
call extract('utime',utime,real8arr,tags,nreal8s,ierrs(3)) |
| 669 |
call extract('umagfd',umagfd,real8arr,tags,nreal8s,ierrs(4)) |
| 670 |
|
| 671 |
! extract the number of dustfrac arrays in the file |
| 672 |
ndusttypes = extract_ndusttypes(tags,tagsreal,intarr,nints) |
| 673 |
! |
| 674 |
!--append real*8s to realarr so they can be used in |
| 675 |
! legends and calculated quantities |
| 676 |
! |
| 677 |
if (nreals+nreal8s <= maxinblock) then |
| 678 |
tagsreal(nreals+1:nreals+nreal8s) = tags(1:nreal8s) |
| 679 |
realarr(nreals+1:nreals+nreal8s) = real(real8arr(1:nreal8s)) |
| 680 |
nreals = nreals + nreal8s |
| 681 |
endif |
| 682 |
|
| 683 |
else |
| 684 |
if (nreal8s >= 4) then |
| 685 |
read(iunit,iostat=ierr) udist,umass,utime,umagfd |
| 686 |
elseif (nreal8s >= 3) then |
| 687 |
read(iunit,iostat=ierr) udist,umass,utime |
| 688 |
umagfd = 1.0 |
| 689 |
else |
| 690 |
print "(a)",'*** WARNING: units not found in file' |
| 691 |
udist = 1.0 |
| 692 |
umass = 1.0 |
| 693 |
utime = 1.0 |
| 694 |
umagfd = 1.0 |
| 695 |
endif |
| 696 |
endif |
| 697 |
if (ierr /= 0) then |
| 698 |
print "(a)",'*** error reading units' |
| 699 |
endif |
| 700 |
! |
| 701 |
!--Total number of array blocks in the file |
| 702 |
! |
| 703 |
read(iunit,iostat=ierr) narrsizes |
| 704 |
if (ierr /= 0) return |
| 705 |
if (debug) print*,' nblocks(total)=',narrsizes |
| 706 |
narrsizes = narrsizes/nblocks |
| 707 |
if (ierr /= 0) then |
| 708 |
print "(a)",'*** error reading number of array sizes ***' |
| 709 |
close(iunit) |
| 710 |
return |
| 711 |
elseif (narrsizes > maxarrsizes) then |
| 712 |
narrsizes = maxarrsizes |
| 713 |
print "(a,i2)",'WARNING: too many array sizes: reading only ',narrsizes |
| 714 |
endif |
| 715 |
if (narrsizes >= 4 .and. nreal8s < 4) then |
| 716 |
print "(a)",' WARNING: could not read magnetic units from dump file' |
| 717 |
endif |
| 718 |
if (debug) print*,' number of array sizes = ',narrsizes |
| 719 |
if (allocated(npartoftype_tmp)) deallocate(npartoftype_tmp) |
| 720 |
|
| 721 |
end subroutine read_header |
| 722 |
|
| 723 |
!---------------------------------------------------------------------- |
| 724 |
! Read the header to each array block |
| 725 |
!---------------------------------------------------------------------- |
| 726 |
subroutine read_block_header(iunit,iblock,iarr,iverbose,debug,& |
| 727 |
isize,nint,nint1,nint2,nint4,nint8,nreal,nreal4,nreal8,& |
| 728 |
ntotblock,npart,ntotal,nptmasstot,ncolstep,ierr) |
| 729 |
integer, intent(in) :: iunit,iblock,iarr,iverbose |
| 730 |
logical, intent(in) :: debug |
| 731 |
integer*8, intent(out) :: isize(:) |
| 732 |
integer, intent(out) :: nint,nint1,nint2,nint4,nint8,nreal,nreal4,nreal8,ierr |
| 733 |
integer, intent(inout) :: ntotblock,npart,ntotal,nptmasstot,ncolstep |
| 734 |
|
| 735 |
read(iunit,iostat=ierr) isize(iarr),nint,nint1,nint2,nint4,nint8,nreal,nreal4,nreal8 |
| 736 |
if (iarr==1) then |
| 737 |
ntotblock = isize(iarr) |
| 738 |
if (npart <= 0) npart = ntotblock |
| 739 |
ntotal = ntotal + ntotblock |
| 740 |
elseif (iarr==2) then |
| 741 |
nptmasstot = nptmasstot + isize(iarr) |
| 742 |
endif |
| 743 |
if (debug) print*,'DEBUG: array size ',iarr,' size = ',isize(iarr) |
| 744 |
if (isize(iarr) > 0 .and. iblock==1) then |
| 745 |
if (iverbose >= 2 .or. debug) print "(1x,a,i1,a,i12,a,5(i2,1x),a,3(i2,1x))", & |
| 746 |
'block ',iarr,' dim = ',isize(iarr),' nint =',nint,nint1,nint2,nint4,nint8,& |
| 747 |
'nreal =',nreal,nreal4,nreal8 |
| 748 |
endif |
| 749 |
!--we are going to read all real arrays but need to convert them all to default real |
| 750 |
if (iarr /= 2 .and. isize(iarr)==isize(1) .and. iblock==1) then |
| 751 |
ncolstep = ncolstep + nreal + nreal4 + nreal8 |
| 752 |
endif |
| 753 |
|
| 754 |
end subroutine read_block_header |
| 755 |
|
| 756 |
!---------------------------------------------------------------------- |
| 757 |
! Extract and print relevant variables from the header block |
| 758 |
!---------------------------------------------------------------------- |
| 759 |
subroutine extract_variables_from_header(tags,realarr,nreals,iverbose,debug,& |
| 760 |
gotbinary,nblocks,nptmasstot,npartoftypei,ntypes,& |
| 761 |
time,gamma,hfact,npart,ntotal,npartoftype,massoftype,dat,ix,ih,ipmass,ivx) |
| 762 |
character(len=lentag), intent(in) :: tags(maxinblock) |
| 763 |
real, intent(in) :: realarr(maxinblock) |
| 764 |
integer, intent(in) :: nreals,iverbose,nblocks,nptmasstot,npartoftypei(:),ntypes |
| 765 |
integer, intent(in) :: ix(3),ih,ipmass,ivx |
| 766 |
real, intent(out) :: time,gamma,hfact,massoftype(:) |
| 767 |
real, intent(inout) :: dat(:,:) |
| 768 |
integer, intent(out) :: npartoftype(:) |
| 769 |
integer, intent(inout) :: npart,ntotal |
| 770 |
logical, intent(in) :: debug |
| 771 |
logical, intent(out) :: gotbinary |
| 772 |
real :: rhozero,tff,radL1,PhiL1,Er,RK2 !,dtmax |
| 773 |
real :: massoftypei(ntypes) |
| 774 |
integer :: i,ierrs(10) |
| 775 |
integer :: itype |
| 776 |
real, parameter :: pi=4.*atan(1.) |
| 777 |
|
| 778 |
if (phantomdump) then |
| 779 |
call extract('time',time,realarr,tags,nreals,ierrs(1)) |
| 780 |
else |
| 781 |
call extract('gt',time,realarr,tags,nreals,ierrs(1)) |
| 782 |
endif |
| 783 |
call extract('gamma',gamma,realarr,tags,nreals,ierrs(2)) |
| 784 |
call extract('rhozero',rhozero,realarr,tags,nreals,ierrs(3)) |
| 785 |
|
| 786 |
!--extract required information from the first block header |
| 787 |
if (rhozero > 0.) then |
| 788 |
tfreefall = sqrt((3. * pi) / (32. * rhozero)) |
| 789 |
tff = time/tfreefall |
| 790 |
else |
| 791 |
tfreefall = 0. |
| 792 |
tff = 0. |
| 793 |
endif |
| 794 |
if (phantomdump) then |
| 795 |
call extract('massoftype',massoftypei(1:ntypes),realarr,tags,nreals,ierrs(4)) |
| 796 |
npartoftype(:) = 0 |
| 797 |
do i=1,ntypes !--map from phantom types to splash types |
| 798 |
itype = itypemap_phantom(int(i,kind=1)) |
| 799 |
if (debug) print*,'DEBUG: npart of type ',itype,' += ',npartoftypei(i) |
| 800 |
npartoftype(itype) = npartoftype(itype) + npartoftypei(i) |
| 801 |
massoftype(itype) = massoftypei(i) |
| 802 |
enddo |
| 803 |
npartoftype(itypemap_sink_phantom) = nptmasstot ! sink particles |
| 804 |
if (debug) print*,'DEBUG: npart of type sink ',itypemap_sink_phantom,' = ',nptmasstot |
| 805 |
! |
| 806 |
!--if Phantom calculation uses the binary potential |
| 807 |
! then read this as two point mass particles |
| 808 |
! |
| 809 |
if (any(tags(1:nreals)=='x1')) then |
| 810 |
gotbinary = .true. |
| 811 |
npartoftype(itypemap_sink_phantom) = npartoftype(itypemap_sink_phantom) + 2 |
| 812 |
ntotal = ntotal + 2 |
| 813 |
call extract('x1',dat(npart+1,ix(1)),realarr,tags,nreals,ierrs(1)) |
| 814 |
call extract('y1',dat(npart+1,ix(2)),realarr,tags,nreals,ierrs(2)) |
| 815 |
call extract('z1',dat(npart+1,ix(3)),realarr,tags,nreals,ierrs(3)) |
| 816 |
if (ipmass > 0) call extract('m1',dat(npart+1,ipmass),realarr,tags,nreals,ierrs(4)) |
| 817 |
call extract('h1',dat(npart+1,ih),realarr,tags,nreals,ierrs(4)) |
| 818 |
if (debug) print *,npart+1,npart+2 |
| 819 |
if (iverbose >= 1) print *,'binary position: primary: ',dat(npart+1,ix(1):ix(3)) |
| 820 |
|
| 821 |
call extract('x2',dat(npart+2,ix(1)),realarr,tags,nreals,ierrs(1)) |
| 822 |
call extract('y2',dat(npart+2,ix(2)),realarr,tags,nreals,ierrs(2)) |
| 823 |
call extract('z2',dat(npart+2,ix(3)),realarr,tags,nreals,ierrs(3)) |
| 824 |
if (ipmass > 0) call extract('m2',dat(npart+2,ipmass),realarr,tags,nreals,ierrs(4)) |
| 825 |
call extract('h2',dat(npart+2,ih),realarr,tags,nreals,ierrs(5)) |
| 826 |
if (iverbose >= 1 .and. ipmass > 0 .and. ih > 0) then |
| 827 |
print *,' secondary: ',dat(npart+2,ix(1):ix(3)) |
| 828 |
print *,' m1: ',dat(npart+1,ipmass),' m2:',dat(npart+2,ipmass),& |
| 829 |
' h1: ',dat(npart+2,ipmass),' h2:',dat(npart+2,ih) |
| 830 |
endif |
| 831 |
if (ivx > 0) then |
| 832 |
call extract('vx1',dat(npart+1,ivx),realarr,tags,nreals,ierrs(1)) |
| 833 |
call extract('vy1',dat(npart+1,ivx+1),realarr,tags,nreals,ierrs(2)) |
| 834 |
call extract('vz1',dat(npart+1,ivx+2),realarr,tags,nreals,ierrs(3)) |
| 835 |
call extract('vx2',dat(npart+2,ivx),realarr,tags,nreals,ierrs(4)) |
| 836 |
call extract('vy2',dat(npart+2,ivx+1),realarr,tags,nreals,ierrs(5)) |
| 837 |
call extract('vz2',dat(npart+2,ivx+2),realarr,tags,nreals,ierrs(6)) |
| 838 |
endif |
| 839 |
npart = npart + 2 |
| 840 |
endif |
| 841 |
else |
| 842 |
npartoftype(:) = 0 |
| 843 |
npartoftype(1) = npart |
| 844 |
npartoftype(2) = max(ntotal - npart,0) |
| 845 |
endif |
| 846 |
hfact = 1.2 |
| 847 |
if (phantomdump) then |
| 848 |
call extract('hfact',hfact,realarr,tags,nreals,ierrs(1)) |
| 849 |
call extract('dtmax',dtmax,realarr,tags,nreals,ierrs(2)) |
| 850 |
if (iverbose > 0) then |
| 851 |
print "(a,es12.4,a,f6.3,a,f5.2)", & |
| 852 |
' time = ',time,' gamma = ',gamma,' hfact = ',hfact |
| 853 |
endif |
| 854 |
elseif (batcode) then |
| 855 |
call extract('radL1',radL1,realarr,tags,nreals,ierrs(1)) |
| 856 |
call extract('PhiL1',PhiL1,realarr,tags,nreals,ierrs(2)) |
| 857 |
call extract('Er',Er,realarr,tags,nreals,ierrs(3)) |
| 858 |
if (iverbose > 0) then |
| 859 |
print "(a,es12.4,a,f9.5,a,f8.4,/,a,es12.4,a,es9.2,a,es10.2)", & |
| 860 |
' time: ',time, ' gamma: ',gamma, ' tsph: ',realarr(2), & |
| 861 |
' radL1: ',radL1,' PhiL1: ',PhiL1,' Er: ',Er |
| 862 |
endif |
| 863 |
else |
| 864 |
call extract('RK2',RK2,realarr,tags,nreals,ierrs(1)) |
| 865 |
call extract('dtmax',dtmax,realarr,tags,nreals,ierrs(2)) |
| 866 |
if (iverbose > 0) then |
| 867 |
print "(a,es12.4,a,f9.5,a,f8.4,/,a,es12.4,a,es9.2,a,es10.2)", & |
| 868 |
' time: ',time, ' gamma: ',gamma, ' RK2: ',RK2, & |
| 869 |
' t/t_ff: ',tff,' rhozero: ',rhozero,' dtmax: ',dtmax |
| 870 |
endif |
| 871 |
endif |
| 872 |
|
| 873 |
end subroutine extract_variables_from_header |
| 874 |
|
| 875 |
!--------------------------------------------------------------- |
| 876 |
! old subroutine for guessing labels in non-tagged sphNG format |
| 877 |
!--------------------------------------------------------------- |
| 878 |
subroutine guess_labels(ncolumns,iamvec,label,labelvec,istartmhd, & |
| 879 |
istart_extra_real4,nmhd,nhydroreal4,ndimV,irho,iBfirst,ivx,& |
| 880 |
iutherm,idivB,iJfirst,iradenergy,icv,udist,utime,units,& |
| 881 |
unitslabel) |
| 882 |
use geometry, only:labelcoord |
| 883 |
use labels, only:make_vector_label |
| 884 |
integer, intent(in) :: ncolumns,istartmhd,istart_extra_real4 |
| 885 |
integer, intent(in) :: nmhd,nhydroreal4,ndimV,irho |
| 886 |
integer, intent(out) :: iBfirst,ivx,iutherm,idivB,iJfirst,iradenergy,icv |
| 887 |
integer, intent(inout) :: iamvec(:) |
| 888 |
character(len=*), intent(inout) :: label(:),labelvec(:),unitslabel(:) |
| 889 |
real(doub_prec), intent(in) :: udist,utime |
| 890 |
real, intent(inout) :: units(:) |
| 891 |
real(doub_prec) :: uergg |
| 892 |
|
| 893 |
!--the following only for mhd small dumps or full dumps |
| 894 |
if (ncolumns >= 7) then |
| 895 |
if (mhddump) then |
| 896 |
iBfirst = irho+1 |
| 897 |
if (.not.smalldump) then |
| 898 |
ivx = iBfirst+ndimV |
| 899 |
iutherm = ivx+ndimV |
| 900 |
|
| 901 |
if (phantomdump) then |
| 902 |
!--phantom MHD full dumps |
| 903 |
if (nmhd >= 4) then |
| 904 |
call make_vector_label('A',istartmhd,ndimV,iamvec,labelvec,label,labelcoord(:,1)) |
| 905 |
if (nmhd >= 7) then |
| 906 |
label(istartmhd+3) = 'Euler beta_{x}' |
| 907 |
label(istartmhd+4) = 'Euler beta_{x}' |
| 908 |
label(istartmhd+5) = 'Euler beta_{y}' |
| 909 |
idivB = istartmhd+2*ndimV |
| 910 |
else |
| 911 |
idivB = istartmhd+ndimV |
| 912 |
endif |
| 913 |
elseif (nmhd >= 3) then |
| 914 |
label(istartmhd) = 'Euler alpha' |
| 915 |
label(istartmhd+1) = 'Euler beta' |
| 916 |
idivB = istartmhd + 2 |
| 917 |
elseif (nmhd >= 2) then |
| 918 |
label(istartmhd) = 'Psi' |
| 919 |
idivB = istartmhd + 1 |
| 920 |
elseif (nmhd >= 1) then |
| 921 |
idivB = istartmhd |
| 922 |
endif |
| 923 |
iJfirst = 0 |
| 924 |
if (ncolumns >= idivB+1) then |
| 925 |
label(idivB+1) = 'alpha_{B}' |
| 926 |
endif |
| 927 |
|
| 928 |
else |
| 929 |
!--sphNG MHD full dumps |
| 930 |
label(iutherm+1) = 'grad h' |
| 931 |
label(iutherm+2) = 'grad soft' |
| 932 |
label(iutherm+3) = 'alpha' |
| 933 |
if (nmhd >= 7 .and. usingvecp) then |
| 934 |
call make_vector_label('A',istartmhd,ndimV,iamvec,labelvec,label,labelcoord(:,1)) |
| 935 |
idivB = istartmhd+ndimV |
| 936 |
elseif (nmhd >= 6 .and. usingeulr) then |
| 937 |
label(istartmhd) = 'Euler alpha' |
| 938 |
label(istartmhd+1) = 'Euler beta' |
| 939 |
idivB = istartmhd + 2 |
| 940 |
elseif (nmhd >= 6) then |
| 941 |
label(istartmhd) = 'psi' |
| 942 |
idivB = istartmhd + 1 |
| 943 |
if (nmhd >= 8) then |
| 944 |
label(istartmhd+2+ndimV+1) = '\eta_{real}' |
| 945 |
label(istartmhd+2+ndimV+2) = '\eta_{art}' |
| 946 |
units(istartmhd+2+ndimV+1:istartmhd+2+ndimV+2) = udist*udist/utime |
| 947 |
unitslabel(istartmhd+2+ndimV+1:istartmhd+2+ndimV+2) = ' [cm^2/s]' |
| 948 |
endif |
| 949 |
if (nmhd >= 14) then |
| 950 |
call make_vector_label('fsym',istartmhd+2+ndimV+3,ndimV,& |
| 951 |
iamvec,labelvec,label,labelcoord(:,1)) |
| 952 |
call make_vector_label('faniso',istartmhd+2+ndimV+6,ndimV,& |
| 953 |
iamvec,labelvec,label,labelcoord(:,1)) |
| 954 |
endif |
| 955 |
elseif (nmhd >= 1) then |
| 956 |
idivB = istartmhd |
| 957 |
endif |
| 958 |
iJfirst = idivB + 1 |
| 959 |
if (ncolumns >= iJfirst+ndimV) then |
| 960 |
label(iJfirst+ndimV) = 'alpha_{B}' |
| 961 |
endif |
| 962 |
endif |
| 963 |
else ! mhd small dump |
| 964 |
if (nhydroreal4 >= 3) iutherm = iBfirst+ndimV |
| 965 |
endif |
| 966 |
elseif (.not.smalldump) then |
| 967 |
! pure hydro full dump |
| 968 |
ivx = irho+1 |
| 969 |
iutherm = ivx + ndimV |
| 970 |
if (phantomdump) then |
| 971 |
if (istart_extra_real4 > 0 .and. istart_extra_real4 < 100) then |
| 972 |
label(istart_extra_real4) = 'alpha' |
| 973 |
label(istart_extra_real4+1) = 'alphau' |
| 974 |
endif |
| 975 |
else |
| 976 |
if (istart_extra_real4 > 0 .and. istart_extra_real4 < 100) then |
| 977 |
label(istart_extra_real4) = 'grad h' |
| 978 |
label(istart_extra_real4+1) = 'grad soft' |
| 979 |
label(istart_extra_real4+2) = 'alpha' |
| 980 |
endif |
| 981 |
endif |
| 982 |
endif |
| 983 |
|
| 984 |
if (phantomdump .and. h2chem) then |
| 985 |
if (smalldump) then |
| 986 |
label(nhydroarrays+nmhdarrays+1) = 'H_2 ratio' |
| 987 |
elseif (.not.smalldump .and. iutherm > 0) then |
| 988 |
label(iutherm+1) = 'H_2 ratio' |
| 989 |
label(iutherm+2) = 'HI abundance' |
| 990 |
label(iutherm+3) = 'proton abundance' |
| 991 |
label(iutherm+4) = 'e^- abundance' |
| 992 |
label(iutherm+5) = 'CO abundance' |
| 993 |
endif |
| 994 |
endif |
| 995 |
if (istartrt > 0 .and. istartrt <= ncolumns .and. rtdump) then ! radiative transfer dump |
| 996 |
iradenergy = istartrt |
| 997 |
label(iradenergy) = 'radiation energy' |
| 998 |
uergg = (udist/utime)**2 |
| 999 |
units(iradenergy) = uergg |
| 1000 |
if (smalldump) then |
| 1001 |
icv = istartrt+1 |
| 1002 |
else |
| 1003 |
label(istartrt+1) = 'opacity' |
| 1004 |
units(istartrt+1) = udist**2/umass |
| 1005 |
icv = istartrt+2 |
| 1006 |
label(istartrt+3) = 'lambda' |
| 1007 |
units(istartrt+3) = 1.0 |
| 1008 |
|
| 1009 |
label(istartrt+4) = 'eddington factor' |
| 1010 |
units(istartrt+4) = 1.0 |
| 1011 |
endif |
| 1012 |
if (icv > 0) then |
| 1013 |
label(icv) = 'u/T' |
| 1014 |
units(icv) = uergg |
| 1015 |
endif |
| 1016 |
else |
| 1017 |
iradenergy = 0 |
| 1018 |
icv = 0 |
| 1019 |
endif |
| 1020 |
endif |
| 1021 |
end subroutine guess_labels |
| 1022 |
|
| 1023 |
integer function assign_column(tag,iarr,ipos,ikind,imaxcolumnread,idustarr,ncolstep) result(icolumn) |
| 1024 |
use labels, only:ih,irho,ix,ipmass |
| 1025 |
character(len=lentag), intent(in) :: tag |
| 1026 |
integer, intent(in) :: iarr,ipos,ikind,ncolstep |
| 1027 |
integer, intent(inout) :: imaxcolumnread |
| 1028 |
integer, intent(inout) :: idustarr |
| 1029 |
|
| 1030 |
if (tagged .and. len_trim(tag) > 0) then |
| 1031 |
! |
| 1032 |
! use the tags to put certain arrays in an assigned place |
| 1033 |
! no matter what type is used for the variable in the file |
| 1034 |
! and no matter what order they appear in the dump file |
| 1035 |
! |
| 1036 |
select case(trim(tag)) |
| 1037 |
case('x') |
| 1038 |
icolumn = ix(1) |
| 1039 |
case('y') |
| 1040 |
icolumn = ix(2) |
| 1041 |
case('z') |
| 1042 |
icolumn = ix(3) |
| 1043 |
case('m') |
| 1044 |
icolumn = ipmass |
| 1045 |
case('h') |
| 1046 |
icolumn = ih |
| 1047 |
case('rho') |
| 1048 |
icolumn = irho |
| 1049 |
case('dustfracsum') |
| 1050 |
idustarr = idustarr + 1 |
| 1051 |
icolumn = nhydroarrays + idustarr |
| 1052 |
case('dustfrac') |
| 1053 |
if (ndustarrays > 0) then |
| 1054 |
idustarr = idustarr + 1 |
| 1055 |
icolumn = nhydroarrays + idustarr |
| 1056 |
else |
| 1057 |
icolumn = max(nhydroarrays + ndustarrays + nmhdarrays + 1,imaxcolumnread + 1) |
| 1058 |
endif |
| 1059 |
case('Bx') |
| 1060 |
icolumn = nhydroarrays + ndustarrays + 1 |
| 1061 |
case('By') |
| 1062 |
icolumn = nhydroarrays + ndustarrays + 2 |
| 1063 |
case('Bz') |
| 1064 |
icolumn = nhydroarrays + ndustarrays + 3 |
| 1065 |
case default |
| 1066 |
icolumn = max(nhydroarrays + ndustarrays + nmhdarrays + 1,imaxcolumnread + 1) |
| 1067 |
if (icolumn > ncolstep) then |
| 1068 |
! check for dustfrac not being present |
| 1069 |
if (idustarr == 0 .and. ndustarrays > 0) icolumn = nhydroarrays + 1 |
| 1070 |
endif |
| 1071 |
if (iarr==1) then |
| 1072 |
if (ikind==4) then ! real*4 array |
| 1073 |
istart_extra_real4 = min(istart_extra_real4,icolumn) |
| 1074 |
if (debug) print*,' istart_extra_real4 = ',istart_extra_real4 |
| 1075 |
endif |
| 1076 |
endif |
| 1077 |
end select |
| 1078 |
else |
| 1079 |
! |
| 1080 |
! this is old code handling the non-tagged format where |
| 1081 |
! particular arrays are assumed to be in particular places |
| 1082 |
! |
| 1083 |
if (ikind==6) then ! default reals |
| 1084 |
if (iarr==1.and.((phantomdump.and.ipos==4) & |
| 1085 |
.or.(.not.phantomdump.and.ipos==6))) then |
| 1086 |
! read x,y,z,m,h and then place arrays after always-present ones |
| 1087 |
! (for phantom read x,y,z only) |
| 1088 |
icolumn = nhydroarrays+nmhdarrays + 1 |
| 1089 |
elseif (.not.phantomdump .and. (iarr==4 .and. ipos <= 3)) then |
| 1090 |
icolumn = nhydroarrays + ipos |
| 1091 |
else |
| 1092 |
icolumn = imaxcolumnread + 1 |
| 1093 |
endif |
| 1094 |
elseif (ikind==4) then ! real*4s |
| 1095 |
if (phantomdump) then |
| 1096 |
if (iarr==1 .and. ipos==1) then |
| 1097 |
icolumn = ih ! h is always first real4 in phantom dumps |
| 1098 |
!!--density depends on h being read |
| 1099 |
!required(ih) = .true. |
| 1100 |
elseif (iarr==4 .and. ipos <= 3) then |
| 1101 |
icolumn = nhydroarrays + ipos |
| 1102 |
else |
| 1103 |
icolumn = max(nhydroarrays+nmhdarrays + 1,imaxcolumnread + 1) |
| 1104 |
if (iarr==1) then |
| 1105 |
istart_extra_real4 = min(istart_extra_real4,icolumn) |
| 1106 |
if (debug) print*,' istart_extra_real4 = ',istart_extra_real4 |
| 1107 |
endif |
| 1108 |
endif |
| 1109 |
else |
| 1110 |
if (iarr==1 .and. ipos==1) then |
| 1111 |
icolumn = irho ! density |
| 1112 |
elseif (iarr==1 .and. smalldump .and. ipos==2) then |
| 1113 |
icolumn = ih ! h which is real4 in small dumps |
| 1114 |
!--this was a bug for sphNG files... |
| 1115 |
!elseif (iarr==4 .and. i <= 3) then |
| 1116 |
! icolumn = nhydroarrays + ipos |
| 1117 |
else |
| 1118 |
icolumn = max(nhydroarrays+nmhdarrays + 1,imaxcolumnread + 1) |
| 1119 |
if (iarr==1) then |
| 1120 |
istart_extra_real4 = min(istart_extra_real4,icolumn) |
| 1121 |
if (debug) print*,' istart_extra_real4 = ',istart_extra_real4 |
| 1122 |
endif |
| 1123 |
endif |
| 1124 |
endif |
| 1125 |
else ! used for untagged format with real*8's |
| 1126 |
icolumn = imaxcolumnread + 1 |
| 1127 |
endif |
| 1128 |
endif |
| 1129 |
if (icolumn < 1 .or. icolumn > ncolstep) then |
| 1130 |
print*,' ERROR in column assignment for '//trim(tag) |
| 1131 |
icolumn = ncolstep ! screw up last entry, but don't seg fault |
| 1132 |
endif |
| 1133 |
|
| 1134 |
imaxcolumnread = max(imaxcolumnread,icolumn) |
| 1135 |
|
| 1136 |
end function assign_column |
| 1137 |
|
| 1138 |
!--------------------------------------------------------------- |
| 1139 |
! function to extract the number of dust arrays |
| 1140 |
!--------------------------------------------------------------- |
| 1141 |
integer function extract_ndusttypes(tags,tagsreal,intarr,nints) result(ndusttypes) |
| 1142 |
character(len=lentag), intent(in) :: tags(maxinblock),tagsreal(maxinblock) |
| 1143 |
integer, intent(in) :: intarr(:),nints |
| 1144 |
integer :: i,idust,ierr,ndustsmall |
| 1145 |
logical :: igotndusttypes |
| 1146 |
|
| 1147 |
! Look for ndusttypes in the header |
| 1148 |
igotndusttypes = .false. |
| 1149 |
do i = 1,maxinblock |
| 1150 |
if (trim(tags(i))=='ndusttypes') igotndusttypes = .true. |
| 1151 |
enddo |
| 1152 |
|
| 1153 |
! Retreive/guess the value of ndusttypes |
| 1154 |
if (igotndusttypes) then |
| 1155 |
call extract('ndusttypes',idust,intarr,tags,nints,ierr) |
| 1156 |
else |
| 1157 |
call extract('ndustsmall',ndustsmall,intarr,tags,nints,ierr,verbose=.false.) |
| 1158 |
call extract('ndustlarge',ndustlarge,intarr,tags,nints,ierr,verbose=.false.) |
| 1159 |
idust = ndustsmall+ndustlarge |
| 1160 |
! For older files where ndusttypes is not output to the header |
| 1161 |
if (ierr /= 0) then |
| 1162 |
idust = 0 |
| 1163 |
do i = 1,maxinblock |
| 1164 |
if (tagsreal(i)=='grainsize') idust = idust + 1 |
| 1165 |
enddo |
| 1166 |
if (idust > 0) then |
| 1167 |
write(*,"(a)") ' Warning! Could not find ndusttypes in header' |
| 1168 |
write(*,"(a,I4)") ' ...counting grainsize arrays...ndusttypes =',idust |
| 1169 |
endif |
| 1170 |
endif |
| 1171 |
endif |
| 1172 |
ndusttypes = idust |
| 1173 |
|
| 1174 |
end function extract_ndusttypes |
| 1175 |
|
| 1176 |
subroutine get_rho_from_h(i1,i2,ih,ipmass,irho,required,npartoftype,massoftype,hfact,dat,iphase,nkilled) |
| 1177 |
integer, intent(in) :: i1,i2,ih,ipmass,irho |
| 1178 |
logical, intent(in) :: required(0:) |
| 1179 |
integer, intent(inout) :: npartoftype(:) |
| 1180 |
real, intent(in) :: massoftype(:),hfact |
| 1181 |
real, intent(inout) :: dat(:,:) |
| 1182 |
integer(kind=int1), intent(inout) :: iphase(:) |
| 1183 |
integer, intent(inout) :: nkilled |
| 1184 |
integer :: itype,k |
| 1185 |
real :: pmassi,hi,rhoi |
| 1186 |
! |
| 1187 |
!--dead particles have -ve smoothing lengths in phantom |
| 1188 |
! so use abs(h) for these particles and hide them |
| 1189 |
! |
| 1190 |
if (any(npartoftype(2:) > 0)) then |
| 1191 |
if (.not.required(ih)) print*,'ERROR: need to read h, but required=F' |
| 1192 |
!--need masses for each type if not all gas |
| 1193 |
if (debug) print*,'DEBUG: phantom: setting h for multiple types ',i1,i2 |
| 1194 |
if (debug) print*,'DEBUG: massoftype = ',massoftype(:) |
| 1195 |
do k=i1,i2 |
| 1196 |
itype = itypemap_phantom(iphase(k)) |
| 1197 |
pmassi = massoftype(itype) |
| 1198 |
hi = dat(k,ih) |
| 1199 |
if (ipmass > 0) pmassi = dat(k,ipmass) |
| 1200 |
if (hi > 0.) then |
| 1201 |
if (required(irho)) dat(k,irho) = pmassi*(hfact/hi)**3 |
| 1202 |
elseif (hi < 0.) then |
| 1203 |
!print*,' accreted: ',k,' type was ',itype,iphase(k) |
| 1204 |
npartoftype(itype) = npartoftype(itype) - 1 |
| 1205 |
npartoftype(itypemap_unknown_phantom) = npartoftype(itypemap_unknown_phantom) + 1 |
| 1206 |
if (required(irho)) dat(k,irho) = pmassi*(hfact/abs(hi))**3 |
| 1207 |
iphase(k) = -1 |
| 1208 |
else ! dead particles |
| 1209 |
npartoftype(itype) = npartoftype(itype) - 1 |
| 1210 |
npartoftype(itypemap_unknown_phantom) = npartoftype(itypemap_unknown_phantom) + 1 |
| 1211 |
nkilled = nkilled + 1 |
| 1212 |
if (required(irho)) dat(k,irho) = 0. |
| 1213 |
iphase(k) = -2 |
| 1214 |
endif |
| 1215 |
enddo |
| 1216 |
else |
| 1217 |
if (.not.required(ih)) print*,'ERROR: need to read h, but required=F' |
| 1218 |
if (debug) print*,'debug: phantom: setting rho for all types' |
| 1219 |
pmassi = massoftype(1) |
| 1220 |
!--assume all particles are gas particles |
| 1221 |
do k=i1,i2 |
| 1222 |
hi = dat(k,ih) |
| 1223 |
if (ipmass > 0) pmassi = dat(k,ipmass) |
| 1224 |
if (hi > 0.) then |
| 1225 |
rhoi = pmassi*(hfact/hi)**3 |
| 1226 |
elseif (hi < 0.) then |
| 1227 |
rhoi = pmassi*(hfact/abs(hi))**3 |
| 1228 |
npartoftype(1) = npartoftype(1) - 1 |
| 1229 |
npartoftype(itypemap_unknown_phantom) = npartoftype(itypemap_unknown_phantom) + 1 |
| 1230 |
iphase(k) = -1 |
| 1231 |
else ! if h = 0. |
| 1232 |
rhoi = 0. |
| 1233 |
npartoftype(1) = npartoftype(1) - 1 |
| 1234 |
npartoftype(itypemap_unknown_phantom) = npartoftype(itypemap_unknown_phantom) + 1 |
| 1235 |
iphase(k) = -2 |
| 1236 |
endif |
| 1237 |
if (required(irho)) dat(k,irho) = rhoi |
| 1238 |
enddo |
| 1239 |
endif |
| 1240 |
|
| 1241 |
end subroutine get_rho_from_h |
| 1242 |
|
| 1243 |
!---------------------------------------------------------------------- |
| 1244 |
! Set a negative smoothing length for merged sinks, so that |
| 1245 |
! they can be ignored when plotting |
| 1246 |
!---------------------------------------------------------------------- |
| 1247 |
subroutine set_sink_merged(i1,i2,ih,ipmass,dat) |
| 1248 |
integer, intent(in) :: i1,i2,ih,ipmass |
| 1249 |
real, intent(inout) :: dat(:,:) |
| 1250 |
integer :: i |
| 1251 |
|
| 1252 |
if (ih > 0 .and. ipmass > 0) then |
| 1253 |
do i=i1,i2 |
| 1254 |
if (dat(i,ipmass) < 0.) dat(i,ih) = -1. |
| 1255 |
enddo |
| 1256 |
endif |
| 1257 |
|
| 1258 |
end subroutine set_sink_merged |
| 1259 |
|
| 1260 |
!---------------------------------------------------------------------- |
| 1261 |
! Set density on sink particles based on the mass and radius |
| 1262 |
! this is useful for opacity rendering, but also provides useful |
| 1263 |
! information rather than just having zero density on sinks |
| 1264 |
!---------------------------------------------------------------------- |
| 1265 |
subroutine set_sink_density(i1,i2,ih,ipmass,irho,dat) |
| 1266 |
integer, intent(in) :: i1,i2,ih,ipmass,irho |
| 1267 |
real, intent(inout) :: dat(:,:) |
| 1268 |
integer :: i |
| 1269 |
|
| 1270 |
if (ih > 0 .and. ipmass > 0 .and. irho > 0) then |
| 1271 |
do i=i1,i2 |
| 1272 |
if (dat(i,ih) > 0.) dat(i,irho) = dat(i,ipmass)/dat(i,ih)**3 |
| 1273 |
enddo |
| 1274 |
endif |
| 1275 |
|
| 1276 |
end subroutine set_sink_density |
| 1277 |
|
| 1278 |
!---------------------------------------------------------------------- |
| 1279 |
! Map sink particle data to splash columns |
| 1280 |
!---------------------------------------------------------------------- |
| 1281 |
integer function map_sink_property_to_column(k,ilocvx,ncolmax) result(iloc) |
| 1282 |
use labels, only:ix,ipmass,ih,ivx |
| 1283 |
integer, intent(in) :: k,ilocvx,ncolmax |
| 1284 |
|
| 1285 |
select case(k) |
| 1286 |
case(1:3) |
| 1287 |
iloc = ix(k) |
| 1288 |
case(4) |
| 1289 |
iloc = ipmass |
| 1290 |
case(5) |
| 1291 |
iloc = ih |
| 1292 |
case default |
| 1293 |
if (k >= ilocvx .and. k < ilocvx+3 .and. ivx > 0) then |
| 1294 |
iloc = ivx + k-ilocvx ! put velocity into correct arrays |
| 1295 |
else |
| 1296 |
iloc = 0 |
| 1297 |
endif |
| 1298 |
end select |
| 1299 |
if (iloc > ncolmax) iloc = 0 ! error occurred |
| 1300 |
|
| 1301 |
end function map_sink_property_to_column |
| 1302 |
|
| 1303 |
!------------------------------------------------------------ |
| 1304 |
! sanity check of the particle type accounting |
| 1305 |
!------------------------------------------------------------ |
| 1306 |
subroutine check_iphase_matches_npartoftype(i1,i2,iphase,npartoftypei,phantomdump) |
| 1307 |
use labels, only:labeltype |
| 1308 |
use params, only:int1 |
| 1309 |
integer, intent(in) :: i1,i2 |
| 1310 |
integer(kind=int1), intent(in) :: iphase(i1:i2) |
| 1311 |
integer, intent(inout) :: npartoftypei(:) |
| 1312 |
logical, intent(in) :: phantomdump |
| 1313 |
integer :: npartoftype_new(size(npartoftypei)) |
| 1314 |
integer :: k,itype |
| 1315 |
|
| 1316 |
npartoftype_new(:) = 0 |
| 1317 |
do k=i1,i2 |
| 1318 |
if (phantomdump) then |
| 1319 |
itype = itypemap_phantom(iphase(k)) |
| 1320 |
else |
| 1321 |
itype = itypemap_sphNG(iphase(k)) |
| 1322 |
endif |
| 1323 |
npartoftype_new(itype) = npartoftype_new(itype) + 1 |
| 1324 |
enddo |
| 1325 |
do k=1,size(npartoftypei) |
| 1326 |
if (npartoftype_new(k) /= npartoftypei(k)) then |
| 1327 |
print*,' WARNING: got ',npartoftype_new(k),& |
| 1328 |
trim(labeltype(k))//' particles, expecting ',npartoftypei(k) |
| 1329 |
npartoftypei(k) = npartoftype_new(k) |
| 1330 |
endif |
| 1331 |
enddo |
| 1332 |
|
| 1333 |
end subroutine check_iphase_matches_npartoftype |
| 1334 |
|
| 1335 |
!------------------------------------------------------------ |
| 1336 |
! allocate and reallocate the iphase array as needed |
| 1337 |
!------------------------------------------------------------ |
| 1338 |
subroutine allocate_iphase(iphase,nmax,phantomdump,gotbinary,nlocbinary) |
| 1339 |
integer*1, allocatable, intent(inout) :: iphase(:) |
| 1340 |
integer, intent(in) :: nmax,nlocbinary |
| 1341 |
logical, intent(in) :: phantomdump,gotbinary |
| 1342 |
integer*1, allocatable :: iphase_old(:) |
| 1343 |
integer :: ncopy |
| 1344 |
|
| 1345 |
if (allocated(iphase)) then |
| 1346 |
iphase_old = iphase ! allocates memory for iphase_old as well |
| 1347 |
deallocate(iphase) |
| 1348 |
endif |
| 1349 |
allocate(iphase(nmax)) |
| 1350 |
|
| 1351 |
if (phantomdump) then |
| 1352 |
iphase(:) = 1 |
| 1353 |
else |
| 1354 |
iphase(:) = 0 |
| 1355 |
endif |
| 1356 |
|
| 1357 |
if (gotbinary) then |
| 1358 |
iphase(nlocbinary) = -3 |
| 1359 |
iphase(nlocbinary+1) = -3 |
| 1360 |
endif |
| 1361 |
|
| 1362 |
if (allocated(iphase_old)) then |
| 1363 |
ncopy = min(size(iphase_old),size(iphase)) |
| 1364 |
iphase(1:ncopy) = iphase_old(1:ncopy) |
| 1365 |
deallocate(iphase_old) |
| 1366 |
endif |
| 1367 |
|
| 1368 |
end subroutine allocate_iphase |
| 1369 |
|
| 1370 |
end module sphNGread |
| 1371 |
|
| 1372 |
!---------------------------------------------------------------------- |
| 1373 |
! Module for read_data_sphNG and set_labels_sphNG routines |
| 1374 |
!---------------------------------------------------------------------- |
| 1375 |
|
| 1376 |
module readdata_sphNG |
| 1377 |
implicit none |
| 1378 |
|
| 1379 |
public :: read_data_sphNG, set_labels_sphNG, file_format_is_sphNG |
| 1380 |
|
| 1381 |
private |
| 1382 |
contains |
| 1383 |
|
| 1384 |
!---------------------------------------------------------------------- |
| 1385 |
! Main read_data_sphNG routine for splash |
| 1386 |
!---------------------------------------------------------------------- |
| 1387 |
subroutine read_data_sphNG(rootname,indexstart,iposn,nstepsread) |
| 1388 |
use particle_data, only:dat,gamma,time,headervals,& |
| 1389 |
iamtype,npartoftype,maxpart,maxstep,maxcol,masstype |
| 1390 |
!use params, only:int1,int8 |
| 1391 |
use settings_data, only:ndim,ndimV,ncolumns,ncalc,required,ipartialread,& |
| 1392 |
lowmemorymode,ntypes,iverbose,ndusttypes |
| 1393 |
use mem_allocation, only:alloc |
| 1394 |
use system_utils, only:lenvironment,renvironment |
| 1395 |
use labels, only:ipmass,irho,ih,ix,ivx,labeltype,print_types,headertags,& |
| 1396 |
iutherm,itemp,ikappa,irhorestframe,labelreq,nreq,get_sink_type |
| 1397 |
use calcquantities, only:calc_quantities |
| 1398 |
use asciiutils, only:make_tags_unique,match_tag |
| 1399 |
use sphNGread |
| 1400 |
use lightcurve_utils, only:get_temp_from_u,ionisation_fraction,get_opacity |
| 1401 |
use readcomposition, only:check_for_composition_file,read_composition |
| 1402 |
use byteswap, only:bs |
| 1403 |
use part_utils, only:locate_nth_particle_of_type |
| 1404 |
integer, intent(in) :: indexstart,iposn |
| 1405 |
integer, intent(out) :: nstepsread |
| 1406 |
character(len=*), intent(in) :: rootname |
| 1407 |
integer :: i,j,k,ierr,iunit |
| 1408 |
integer :: intg1,int2,int3,ilocvx,iversion |
| 1409 |
integer :: i1,iarr,i2,iptmass1,iptmass2 |
| 1410 |
integer :: npart_max,nstep_max,ncolstep,icolumn,idustarr,nptmasstot |
| 1411 |
integer :: narrsizes |
| 1412 |
integer :: nskip,ntotal,npart,n1,ngas,nreals |
| 1413 |
integer :: iblock,nblocks,ntotblock,ncolcopy |
| 1414 |
integer :: ipos,nptmass,nptmassi,ndust,nstar,nunknown,ilastrequired |
| 1415 |
integer :: imaxcolumnread,nhydroarraysinfile,nhdr,nkilled |
| 1416 |
integer :: itype,iphaseminthistype,iphasemaxthistype,nthistype,iloc,idenscol |
| 1417 |
integer :: icentre,icomp_col_start,ncomp,isink1 |
| 1418 |
integer, dimension(maxparttypes) :: npartoftypei |
| 1419 |
real, dimension(maxparttypes) :: massoftypei |
| 1420 |
logical :: iexist, doubleprec,imadepmasscolumn,gotbinary,gotiphase |
| 1421 |
|
| 1422 |
character(len=len(rootname)+10) :: dumpfile,compfile |
| 1423 |
character(len=100) :: fileident |
| 1424 |
|
| 1425 |
integer*8, dimension(maxarrsizes) :: isize |
| 1426 |
integer, dimension(maxarrsizes) :: nint,nint1,nint2,nint4,nint8,nreal,nreal4,nreal8 |
| 1427 |
integer*1, dimension(:), allocatable :: iphase,level |
| 1428 |
integer, dimension(:), allocatable :: listpm |
| 1429 |
real(doub_prec), dimension(:), allocatable :: dattemp |
| 1430 |
real*4, dimension(:), allocatable :: dattempsingle,massfac |
| 1431 |
real(doub_prec) :: r8,unit_dens,unit_ergg |
| 1432 |
real(sing_prec) :: r4 |
| 1433 |
real, dimension(:,:), allocatable :: dattemp2 |
| 1434 |
real, dimension(maxinblock) :: dummyreal |
| 1435 |
real :: hfact,omega |
| 1436 |
real(doub_prec) :: Xfrac,Yfrac |
| 1437 |
real :: xHIi,xHIIi,xHeIi,xHeIIi,xHeIIIi,nei,m1,rad_corotate |
| 1438 |
logical :: skip_corrupted_block_3,get_temperature,get_kappa,get_kappa_tot |
| 1439 |
logical :: get_ionfrac,need_to_allocate_iphase,need_to_allocate_iorig,got_tag,got_iorig |
| 1440 |
integer(kind=8), dimension(:), allocatable :: iorig |
| 1441 |
character(len=lentag) :: tagsreal(maxinblock), tagtmp |
| 1442 |
|
| 1443 |
integer, parameter :: splash_max_iversion = 1 |
| 1444 |
real, parameter :: Xfrac_default=0.69843,Yfrac_default=0.28731 |
| 1445 |
|
| 1446 |
nstepsread = 0 |
| 1447 |
nstep_max = 0 |
| 1448 |
npart_max = maxpart |
| 1449 |
npart = 0 |
| 1450 |
iunit = 15 |
| 1451 |
ipmass = 4 |
| 1452 |
idivvcol = 0 |
| 1453 |
idivvxcol = 0 |
| 1454 |
icurlvxcol = 0 |
| 1455 |
icurlvycol = 0 |
| 1456 |
icurlvzcol = 0 |
| 1457 |
iHIIcol = 0 |
| 1458 |
iHeIIcol = 0 |
| 1459 |
iHeIIIcol = 0 |
| 1460 |
nhydroreal4 = 0 |
| 1461 |
umass = 1.d0 |
| 1462 |
utime = 1.d0 |
| 1463 |
udist = 1.d0 |
| 1464 |
umagfd = 1.d0 |
| 1465 |
istartmhd = 0 |
| 1466 |
istartrt = 0 |
| 1467 |
istart_extra_real4 = 100 |
| 1468 |
nmhd = 0 |
| 1469 |
igotmass = .false. |
| 1470 |
tfreefall = 1.d0 |
| 1471 |
gotbinary = .false. |
| 1472 |
gotiphase = .false. |
| 1473 |
skip_corrupted_block_3 = .false. |
| 1474 |
got_iorig = .false. |
| 1475 |
|
| 1476 |
dumpfile = trim(rootname) |
| 1477 |
! |
| 1478 |
!--check if data file exists |
| 1479 |
! |
| 1480 |
inquire(file=dumpfile,exist=iexist) |
| 1481 |
if (.not.iexist) then |
| 1482 |
print "(a)",' *** error: '//trim(dumpfile)//': file not found ***' |
| 1483 |
return |
| 1484 |
endif |
| 1485 |
! |
| 1486 |
!--fix number of spatial dimensions |
| 1487 |
! |
| 1488 |
ndim = 3 |
| 1489 |
ndimV = 3 |
| 1490 |
|
| 1491 |
j = indexstart |
| 1492 |
nstepsread = 0 |
| 1493 |
doubleprec = .true. |
| 1494 |
get_temperature = lenvironment("SPLASH_GET_TEMP") |
| 1495 |
get_kappa_tot = lenvironment("SPLASH_GET_KAPPATOT") |
| 1496 |
get_kappa = lenvironment("SPLASH_GET_KAPPA") .or. get_kappa_tot |
| 1497 |
get_ionfrac = lenvironment("SPLASH_GET_ION") |
| 1498 |
if ((get_temperature .or. get_kappa) .and. itempcol > 0 .and. required(itempcol)) then |
| 1499 |
required(irho) = .true. |
| 1500 |
required(irhorestframe) = .true. |
| 1501 |
required(iutherm) = .true. |
| 1502 |
endif |
| 1503 |
if (get_ionfrac .or. get_kappa) then |
| 1504 |
required(irho) = .true. |
| 1505 |
required(itemp) = .true. |
| 1506 |
Xfrac = renvironment("SPLASH_XFRAC",Xfrac_default) |
| 1507 |
Yfrac = renvironment("SPLASH_YFRAC",Yfrac_default) |
| 1508 |
|
| 1509 |
if ( Xfrac < 0. .or. Xfrac > 1.) then |
| 1510 |
Xfrac = Xfrac_default |
| 1511 |
print "(1x,a,f5.3)",'ERROR: Input Xfrac is not between 0 and 1, using default value of ',Xfrac |
| 1512 |
endif |
| 1513 |
if ( Yfrac < 0. .or. Yfrac > 1.) then |
| 1514 |
Yfrac = Yfrac_default |
| 1515 |
print "(1x,a,f5.3)",'ERROR: Input Yfrac is not between 0 and 1, using default value of ',Yfrac |
| 1516 |
endif |
| 1517 |
if ( Xfrac + Yfrac > 1.) then |
| 1518 |
print "(1x,a,f5.3,a,f5.3,a,f5.3)",'ERROR: Xfrac + Yfrac = ',Xfrac+Yfrac,' exceeds 1. Using default values of Xfrac = ',& |
| 1519 |
Xfrac_default,' and Yfrac = ',Yfrac_default |
| 1520 |
Xfrac = Xfrac_default |
| 1521 |
Yfrac = Yfrac_default |
| 1522 |
endif |
| 1523 |
endif |
| 1524 |
ilastrequired = 0 |
| 1525 |
do i=1,size(required)-1 |
| 1526 |
if (required(i)) ilastrequired = i |
| 1527 |
enddo |
| 1528 |
|
| 1529 |
if (iverbose >= 1) print "(1x,a)",'reading sphNG format' |
| 1530 |
write(*,"(26('>'),1x,a,1x,26('<'))") trim(dumpfile) |
| 1531 |
|
| 1532 |
debug = lenvironment('SSPLASH_DEBUG') |
| 1533 |
if (debug) iverbose = 1 |
| 1534 |
! |
| 1535 |
!--open the (unformatted) binary file |
| 1536 |
! |
| 1537 |
open(unit=iunit,iostat=ierr,file=dumpfile,status='old',form='unformatted') |
| 1538 |
if (ierr /= 0) then |
| 1539 |
print "(a)",'*** ERROR OPENING '//trim(dumpfile)//' ***' |
| 1540 |
return |
| 1541 |
else |
| 1542 |
! |
| 1543 |
!--read header key to work out precision |
| 1544 |
! |
| 1545 |
doubleprec = .true. |
| 1546 |
read(iunit,iostat=ierr) intg1,r8,int2,iversion,int3 |
| 1547 |
if (intg1 /= 690706 .and. intg1 /= 060769) then |
| 1548 |
if (bs(intg1)==690706 .or. bs(intg1)==060769) then |
| 1549 |
print "(a)",'*** ERROR: file is wrong endian, try:' |
| 1550 |
print "(/,4x,a,/,/,6x,a,/)",'export GFORTRAN_CONVERT_UNIT=big_endian','or, with ifort:' |
| 1551 |
print "(4x,a)",'export F_UFMTENDIAN=big' |
| 1552 |
close(iunit) |
| 1553 |
return |
| 1554 |
else |
| 1555 |
print "(a)",'*** ERROR READING HEADER: corrupt file/zero size/wrong endian?' |
| 1556 |
close(iunit) |
| 1557 |
return |
| 1558 |
endif |
| 1559 |
endif |
| 1560 |
if (int2 /= 780806 .and. int2 /= 060878) then |
| 1561 |
if (iverbose >= 2) print "(a)",' single precision dump' |
| 1562 |
rewind(iunit) |
| 1563 |
read(iunit,iostat=ierr) intg1,r4,int2,iversion,int3 |
| 1564 |
if (int2 /= 780806 .and. int2 /= 060878) then |
| 1565 |
print "(a)",'ERROR determining single/double precision in file header' |
| 1566 |
endif |
| 1567 |
doubleprec = .false. |
| 1568 |
elseif (int3 /= 690706) then |
| 1569 |
print*,' got ',intg1,r4,int2,iversion,int3 |
| 1570 |
print "(a)",'*** WARNING: default int appears to be int*8: not implemented' |
| 1571 |
else |
| 1572 |
if (debug) print "(a)",' double precision dump' ! no need to print this |
| 1573 |
endif |
| 1574 |
if (iversion==690706) then ! handle old-format files (without version number) gracefully |
| 1575 |
iversion = 0 |
| 1576 |
endif |
| 1577 |
endif |
| 1578 |
if (iversion > splash_max_iversion) then |
| 1579 |
print "(/a,i2,/,a,i2)",& |
| 1580 |
' *** WARNING: this copy of splash can only read version ',splash_max_iversion, & |
| 1581 |
' but the file format version is ',iversion |
| 1582 |
if (.not.lenvironment('SSPLASH_IGNORE_IVERSION')) then |
| 1583 |
print "(2(/,a))",' ** press any key to bravely proceed anyway ** ', & |
| 1584 |
' (set SSPLASH_IGNORE_IVERSION=yes to silence this warning)' |
| 1585 |
read* |
| 1586 |
endif |
| 1587 |
endif |
| 1588 |
! |
| 1589 |
!--read file ID |
| 1590 |
! |
| 1591 |
read(iunit,iostat=ierr) fileident |
| 1592 |
if (ierr /=0) then |
| 1593 |
print "(a)",'*** ERROR READING FILE ID ***' |
| 1594 |
close(iunit) |
| 1595 |
return |
| 1596 |
else |
| 1597 |
if (iverbose >= 0) print "(1x,a)",trim(fileident) |
| 1598 |
endif |
| 1599 |
mhddump = .false. |
| 1600 |
rtdump = .false. |
| 1601 |
call get_options_from_fileident(fileident,smalldump,tagged,phantomdump,& |
| 1602 |
usingvecp,usingeulr,cleaning,h2chem,rt_in_header,batcode) |
| 1603 |
if (tagged .and. iversion < 1) print "(a)",'ERROR: got tagged format but iversion is ',iversion |
| 1604 |
! |
| 1605 |
!--read variables from header |
| 1606 |
! |
| 1607 |
call read_header(iunit,iverbose,debug,doubleprec, & |
| 1608 |
npart,npartoftypei,n1,ntypes,nblocks,narrsizes,dummyreal,tagsreal,nreals,ierr) |
| 1609 |
if (ierr /= 0) then |
| 1610 |
print "(a)",' *** ERROR READING HEADER ***' |
| 1611 |
close(iunit) |
| 1612 |
return |
| 1613 |
endif |
| 1614 |
! |
| 1615 |
!--Attempt to read all MPI blocks |
| 1616 |
! |
| 1617 |
ntotal = 0 |
| 1618 |
ntotblock = 0 |
| 1619 |
nptmasstot = 0 |
| 1620 |
i2 = 0 |
| 1621 |
iptmass2 = 0 |
| 1622 |
igotmass = .true. |
| 1623 |
imadepmasscolumn = .false. |
| 1624 |
massoftypei(:) = 0. |
| 1625 |
nkilled = 0 |
| 1626 |
|
| 1627 |
over_MPIblocks: do iblock=1,nblocks |
| 1628 |
! |
| 1629 |
!--read array header from this block |
| 1630 |
! |
| 1631 |
if (iblock==1) ncolstep = 0 |
| 1632 |
do iarr=1,narrsizes |
| 1633 |
call read_block_header(iunit,iblock,iarr,iverbose,debug, & |
| 1634 |
isize,nint(iarr),nint1(iarr),nint2(iarr),nint4(iarr),nint8(iarr),& |
| 1635 |
nreal(iarr),nreal4(iarr),nreal8(iarr),& |
| 1636 |
ntotblock,npart,ntotal,nptmasstot,ncolstep,ierr) |
| 1637 |
if (ierr /= 0) then |
| 1638 |
print "(a)",' *** ERROR READING ARRAY SIZES ***' |
| 1639 |
close(iunit) |
| 1640 |
return |
| 1641 |
endif |
| 1642 |
enddo |
| 1643 |
if (debug) print*,'DEBUG: ncolstep=',ncolstep,' from file header, also nptmasstot = ',nptmasstot |
| 1644 |
! |
| 1645 |
!--this is a bug fix for a corrupt version of wdump outputting bad |
| 1646 |
! small dump files |
| 1647 |
! |
| 1648 |
if (smalldump .and. nreal(1)==5 .and. iblock==1 .and. lenvironment('SSPLASH_FIX_CORRUPT')) then |
| 1649 |
print*,'FIXING CORRUPT HEADER ON SMALL DUMPS: assuming nreal=3 not 5' |
| 1650 |
nreal(1) = 3 |
| 1651 |
ncolstep = ncolstep - 2 |
| 1652 |
endif |
| 1653 |
|
| 1654 |
npart_max = maxval(isize(1:narrsizes)) |
| 1655 |
npart_max = max(npart_max,npart+nptmasstot,ntotal) |
| 1656 |
! |
| 1657 |
!--work out from array header how many columns we are going to read |
| 1658 |
! in order to allocate memory |
| 1659 |
! |
| 1660 |
if (iblock==1) then |
| 1661 |
igotmass = .true. |
| 1662 |
if (smalldump .or. phantomdump) then |
| 1663 |
if (phantomdump) then |
| 1664 |
if (tagged) then |
| 1665 |
call extract('massoftype',massoftypei(1:ntypes),dummyreal,tagsreal,nreals,ierr) |
| 1666 |
else |
| 1667 |
! old phantom dumps had only 5 types |
| 1668 |
call extract('massoftype',massoftypei(1:5),dummyreal,tagsreal,nreals,ierr) |
| 1669 |
endif |
| 1670 |
else |
| 1671 |
call extract('pmassinitial',massoftypei(1),dummyreal,tagsreal,nreals,ierr) |
| 1672 |
if (ierr /= 0) then |
| 1673 |
print "(a)",' error extracting particle mass from small dump file' |
| 1674 |
massoftypei(1) = 0. |
| 1675 |
igotmass = .false. |
| 1676 |
endif |
| 1677 |
endif |
| 1678 |
if (debug) print*,'DEBUG: got massoftype(gas) = ',massoftypei(1) |
| 1679 |
if (any(massoftypei(1:ntypes) > tiny(0.)) .and. .not.lowmemorymode) then |
| 1680 |
ncolstep = ncolstep + 1 ! make an extra column to contain particle mass |
| 1681 |
imadepmasscolumn = .true. |
| 1682 |
elseif (lowmemorymode) then |
| 1683 |
igotmass = .false. |
| 1684 |
else |
| 1685 |
igotmass = .false. |
| 1686 |
endif |
| 1687 |
if (all(abs(massoftypei(1:ntypes)) < tiny(0.)) .and. nreal(1) < 4) then |
| 1688 |
print "(a)",' error: particle masses not present in small dump file' |
| 1689 |
igotmass = .false. |
| 1690 |
endif |
| 1691 |
endif |
| 1692 |
if (debug) print*,'DEBUG: gotmass = ',igotmass, ' ncolstep = ',ncolstep |
| 1693 |
! |
| 1694 |
!-- to handle both small and full dumps, we need to place the quantities dumped |
| 1695 |
! in both small and full dumps at the start of the dat array |
| 1696 |
! quantities only in the full dump then come after |
| 1697 |
! also means that hydro/MHD are "semi-compatible" in the sense that x,y,z,m,h |
| 1698 |
! and rho are in the same place for both types of dump |
| 1699 |
! |
| 1700 |
ix(1) = 1 |
| 1701 |
ix(2) = 2 |
| 1702 |
ix(3) = 3 |
| 1703 |
if (igotmass) then |
| 1704 |
ipmass = 4 |
| 1705 |
ih = 5 |
| 1706 |
irho = 6 |
| 1707 |
nhydroarrays = 6 ! x,y,z,m,h,rho |
| 1708 |
else |
| 1709 |
ipmass = 0 |
| 1710 |
ih = 4 |
| 1711 |
irho = 5 |
| 1712 |
nhydroarrays = 5 ! x,y,z,h,rho |
| 1713 |
endif |
| 1714 |
nhydroarraysinfile = nreal(1) + nreal4(1) + nreal8(1) |
| 1715 |
nhydroreal4 = nreal4(1) |
| 1716 |
if (imadepmasscolumn) nhydroarraysinfile = nhydroarraysinfile + 1 |
| 1717 |
if (nhydroarraysinfile < nhydroarrays .and. .not.phantomdump) then |
| 1718 |
print "(a)",' ERROR: one of x,y,z,m,h or rho missing in small dump read' |
| 1719 |
nhydroarrays = nreal(1)+nreal4(1)+nreal8(1) |
| 1720 |
elseif (phantomdump .and. (nreal(1) < 3 .or. nreal4(1) < 1)) then |
| 1721 |
print "(a)",' ERROR: x,y,z or h missing in phantom read' |
| 1722 |
endif |
| 1723 |
ndustarrays = ndusttypes |
| 1724 |
if (debug) print*,' DEBUG: ndustarrays = ',ndustarrays |
| 1725 |
if (narrsizes >= 4) then |
| 1726 |
nmhdarrays = 3 ! Bx,By,Bz |
| 1727 |
nmhd = nreal(4) + nreal4(4) + nreal8(4) - nmhdarrays ! how many "extra" mhd arrays |
| 1728 |
if (debug) print*,'DEBUG: ',nmhd,' extra MHD arrays' |
| 1729 |
else |
| 1730 |
nmhdarrays = 0 |
| 1731 |
endif |
| 1732 |
|
| 1733 |
!--radiative transfer dump? |
| 1734 |
if (narrsizes >= 3 .and. isize(3)==isize(1)) rtdump = .true. |
| 1735 |
!--mhd dump? |
| 1736 |
if (narrsizes >= 4) mhddump = .true. |
| 1737 |
|
| 1738 |
if (.not.(mhddump.or.smalldump)) then |
| 1739 |
ivx = nhydroarrays+ndustarrays+1 |
| 1740 |
elseif (mhddump .and. .not.smalldump) then |
| 1741 |
ivx = nhydroarrays+ndustarrays+nmhdarrays+1 |
| 1742 |
else |
| 1743 |
ivx = 0 |
| 1744 |
endif |
| 1745 |
!--need to force read of velocities e.g. for corotating frame subtraction |
| 1746 |
if (any(required(ivx:ivx+ndimV-1))) required(ivx:ivx+ndimV-1) = .true. |
| 1747 |
|
| 1748 |
!--force read of h and rho if dustfrac is required |
| 1749 |
if (ndustarrays > 0 .and. any(required(nhydroarrays+1:nhydroarrays+ndustarrays))) then |
| 1750 |
if (debug) print*,' dustfrac in columns ',nhydroarrays+1,nhydroarrays+ndustarrays,' required = ',required(nhydroarrays+1) |
| 1751 |
required(irho) = .true. |
| 1752 |
required(ih) = .true. |
| 1753 |
endif |
| 1754 |
|
| 1755 |
!--always read mass and h if density is needed, as rho is constructed from m and h |
| 1756 |
if (required(irho)) then |
| 1757 |
required(ipmass) = .true. |
| 1758 |
required(ih) = .true. |
| 1759 |
endif |
| 1760 |
|
| 1761 |
!--for phantom dumps, also make a column for density |
| 1762 |
! and divv, if a .divv file exists |
| 1763 |
if (phantomdump) then |
| 1764 |
ncolstep = ncolstep + 1 |
| 1765 |
! make extra columns in the same place every time |
| 1766 |
if (maxcol==0) then |
| 1767 |
ncolstepfirst = ncolstep ! save number of columns |
| 1768 |
elseif (ncolstep < ncolstepfirst) then |
| 1769 |
ncolstep = ncolstepfirst ! used saved number of columns |
| 1770 |
endif |
| 1771 |
inquire(file=trim(dumpfile)//'.divv',exist=iexist) |
| 1772 |
if (iexist) then |
| 1773 |
idivvxcol = ncolstep + 1 |
| 1774 |
icurlvxcol = ncolstep + 2 |
| 1775 |
icurlvycol = ncolstep + 3 |
| 1776 |
icurlvzcol = ncolstep + 4 |
| 1777 |
ncolstep = ncolstep + 4 |
| 1778 |
endif |
| 1779 |
if (get_temperature) then |
| 1780 |
!add a column for the temperature |
| 1781 |
ncolstep = ncolstep+1 |
| 1782 |
itempcol = ncolstep |
| 1783 |
endif |
| 1784 |
if (get_kappa) then |
| 1785 |
ncolstep = ncolstep+1 |
| 1786 |
ikappa = ncolstep |
| 1787 |
endif |
| 1788 |
if (get_ionfrac) then |
| 1789 |
iHIIcol = ncolstep + 1 |
| 1790 |
iHeIIcol = ncolstep + 2 |
| 1791 |
iHeIIIcol = ncolstep + 3 |
| 1792 |
ncolstep = ncolstep + 3 |
| 1793 |
endif |
| 1794 |
call check_for_composition_file(trim(dumpfile),& |
| 1795 |
npart,ncolstep,icomp_col_start,ncomp,tagarr,compfile) |
| 1796 |
endif |
| 1797 |
endif |
| 1798 |
! |
| 1799 |
!--allocate memory now that we know the number of columns |
| 1800 |
! |
| 1801 |
if (iblock==1) then |
| 1802 |
ncolumns = ncolstep + ncalc |
| 1803 |
if (ncolumns > maxplot) then |
| 1804 |
print*,'ERROR with ncolumns = ',ncolumns,' in data read' |
| 1805 |
return |
| 1806 |
endif |
| 1807 |
ilastrequired = 0 |
| 1808 |
do i=1,ncolumns |
| 1809 |
if (required(i)) ilastrequired = i |
| 1810 |
enddo |
| 1811 |
endif |
| 1812 |
|
| 1813 |
need_to_allocate_iphase = (npart_max > maxpart) .or. .not.allocated(iphase) |
| 1814 |
need_to_allocate_iorig = (ncomp > 0) |
| 1815 |
if (npart_max > maxpart .or. j > maxstep .or. ncolumns > maxcol) then |
| 1816 |
if (lowmemorymode) then |
| 1817 |
call alloc(max(npart_max+2,maxpart),j,ilastrequired) |
| 1818 |
else |
| 1819 |
call alloc(max(npart_max+2,maxpart),j,ncolumns,mixedtypes=.true.) |
| 1820 |
endif |
| 1821 |
endif |
| 1822 |
! |
| 1823 |
!--now that memory has been allocated, copy info from the header into |
| 1824 |
! the relevant arrays |
| 1825 |
! |
| 1826 |
if (iblock==1) then |
| 1827 |
call extract_variables_from_header(tagsreal,dummyreal,nreals,iverbose,debug, & |
| 1828 |
gotbinary,nblocks,nptmasstot,npartoftypei,ntypes,& |
| 1829 |
time(j),gamma(j),hfact,npart,ntotal,npartoftype(:,j),masstype(:,j), & |
| 1830 |
dat(:,:,j),ix,ih,ipmass,ivx) |
| 1831 |
nhdr = min(nreals,maxhdr) |
| 1832 |
headervals(1:nhdr,j) = dummyreal(1:nhdr) |
| 1833 |
headertags(1:nhdr) = tagsreal(1:nhdr) |
| 1834 |
|
| 1835 |
call set_grain_sizes(nhdr,headertags,headervals(:,j),udist) ! get grain sizes in cm |
| 1836 |
call make_tags_unique(nhdr,headertags) |
| 1837 |
if (iverbose > 0) call print_dustgrid_info(nhdr,headertags,headervals(:,j),masstype(1,j)*npartoftype(1,j)) |
| 1838 |
|
| 1839 |
nstepsread = nstepsread + 1 |
| 1840 |
! |
| 1841 |
!--stop reading file here if no columns required |
| 1842 |
! |
| 1843 |
if (ilastrequired==0) exit over_MPIblocks |
| 1844 |
endif |
| 1845 |
! |
| 1846 |
!--allocate memory for iphase array now that gotbinary is known |
| 1847 |
! |
| 1848 |
if (need_to_allocate_iphase) call allocate_iphase(iphase,max(npart_max+2,maxpart),phantomdump,gotbinary,npart_max+1) |
| 1849 |
if (need_to_allocate_iorig) allocate(iorig(max(npart_max+2,maxpart))) |
| 1850 |
! |
| 1851 |
!--Arrays |
| 1852 |
! |
| 1853 |
imaxcolumnread = 0 |
| 1854 |
icolumn = 0 |
| 1855 |
idustarr = 0 |
| 1856 |
istartmhd = 0 |
| 1857 |
istartrt = 0 |
| 1858 |
i1 = i2 + 1 |
| 1859 |
i2 = i1 + isize(1) - 1 |
| 1860 |
if (debug) then |
| 1861 |
print "(1x,a10,i4,3(a,i12))",'MPI block ',iblock,': particles: ',i1,' to ',i2,' of ',npart |
| 1862 |
elseif (nblocks > 1) then |
| 1863 |
if (iblock==1) write(*,"(a,i1,a)",ADVANCE="no") ' reading MPI blocks: .' |
| 1864 |
write(*,"('.')",ADVANCE="no") |
| 1865 |
endif |
| 1866 |
iptmass1 = iptmass2 + 1 |
| 1867 |
iptmass2 = iptmass1 + isize(2) - 1 |
| 1868 |
nptmass = nptmasstot |
| 1869 |
if (nptmass > 0 .and. debug) print "(15x,3(a,i12))",' pt. masses: ',iptmass1,' to ',iptmass2,' of ',nptmass |
| 1870 |
|
| 1871 |
do iarr=1,narrsizes |
| 1872 |
if (nreal(iarr) + nreal4(iarr) + nreal8(iarr) > 0) then |
| 1873 |
if (iarr==4) then |
| 1874 |
istartmhd = imaxcolumnread + 1 |
| 1875 |
if (debug) print*,' istartmhd = ',istartmhd |
| 1876 |
elseif (iarr==3 .and. rtdump) then |
| 1877 |
istartrt = max(nhydroarrays+nmhdarrays+1,imaxcolumnread + 1) |
| 1878 |
if (debug) print*,' istartrt = ',istartrt |
| 1879 |
endif |
| 1880 |
endif |
| 1881 |
!--read iphase from array block 1 |
| 1882 |
got_tag = .false. |
| 1883 |
if (iarr==1) then |
| 1884 |
!--skip default int |
| 1885 |
nskip = nint(iarr) |
| 1886 |
do i=1,nskip |
| 1887 |
if (tagged) read(iunit,end=33,iostat=ierr) ! skip tags |
| 1888 |
read(iunit,end=33,iostat=ierr) |
| 1889 |
enddo |
| 1890 |
if (nint1(iarr) < 1 .and. nint8(iarr) < 1) then |
| 1891 |
if (.not.phantomdump .or. any(npartoftypei(2:) > 0)) then |
| 1892 |
if (iverbose > 0) print "(a)",' WARNING: can''t locate iphase in dump' |
| 1893 |
elseif (phantomdump) then |
| 1894 |
if (iverbose > 0) print "(a)",' WARNING: can''t locate iphase in dump' |
| 1895 |
endif |
| 1896 |
gotiphase = .false. |
| 1897 |
!--skip remaining integer arrays |
| 1898 |
nskip = nint1(iarr) + nint2(iarr) + nint4(iarr) + nint8(iarr) |
| 1899 |
else |
| 1900 |
if (tagged) read(iunit,end=33,iostat=ierr) tagtmp |
| 1901 |
select case(tagtmp) |
| 1902 |
case('iphase','itype') |
| 1903 |
gotiphase = .true. |
| 1904 |
read(iunit,end=33,iostat=ierr) iphase(i1:i2) |
| 1905 |
!--skip remaining integer arrays |
| 1906 |
nskip = nint1(iarr) - 1 + nint2(iarr) + nint4(iarr) + nint8(iarr) |
| 1907 |
case('iorig') |
| 1908 |
if (allocated(iorig)) then |
| 1909 |
read(iunit,end=33,iostat=ierr) iorig(i1:i2) |
| 1910 |
got_iorig = .true. |
| 1911 |
else |
| 1912 |
read(iunit,end=33,iostat=ierr) |
| 1913 |
got_iorig = .false. |
| 1914 |
endif |
| 1915 |
nskip = nint1(iarr) - 1 + nint2(iarr) + nint4(iarr) + nint8(iarr) |
| 1916 |
case default |
| 1917 |
got_tag = .true. ! needed because we already read the tag |
| 1918 |
!--skip all integer arrays |
| 1919 |
nskip = nint1(iarr) + nint2(iarr) + nint4(iarr) + nint8(iarr) |
| 1920 |
end select |
| 1921 |
endif |
| 1922 |
elseif (smalldump .and. iarr==2 .and. isize(iarr) > 0 .and. .not.phantomdump) then |
| 1923 |
!--read listpm from array block 2 for small dumps (needed here to extract sink masses) |
| 1924 |
if (allocated(listpm)) deallocate(listpm) |
| 1925 |
allocate(listpm(isize(iarr))) |
| 1926 |
if (nint(iarr) < 1) then |
| 1927 |
print "(a)",'ERROR: can''t locate listpm in dump' |
| 1928 |
nskip = nint(iarr) + nint1(iarr) + nint2(iarr) + nint4(iarr) + nint8(iarr) |
| 1929 |
else |
| 1930 |
if (tagged) read(iunit,end=33,iostat=ierr) ! skip tags |
| 1931 |
read(iunit,end=33,iostat=ierr) listpm(1:isize(iarr)) |
| 1932 |
nskip = nint(iarr) - 1 + nint1(iarr) + nint2(iarr) + nint4(iarr) + nint8(iarr) |
| 1933 |
endif |
| 1934 |
else |
| 1935 |
!--otherwise skip all integer arrays (not needed for plotting) |
| 1936 |
nskip = nint(iarr) + nint1(iarr) + nint2(iarr) + nint4(iarr) + nint8(iarr) |
| 1937 |
endif |
| 1938 |
|
| 1939 |
if (iarr==3 .and. lenvironment('SSPLASH_BEN_HACKED')) then |
| 1940 |
nskip = nskip - 1 |
| 1941 |
print*,' FIXING HACKED DUMP FILE' |
| 1942 |
endif |
| 1943 |
!print*,'skipping ',nskip |
| 1944 |
do i=1,nskip |
| 1945 |
if (tagged .and. .not.got_tag) read(iunit,end=33,iostat=ierr) tagtmp ! read tag, unless already read |
| 1946 |
got_tag = .false. ! must reset this flag otherwise get corrupted read |
| 1947 |
! |
| 1948 |
! read the Adaptive Particle Refinement level array |
| 1949 |
! in order to correctly set particle masses, if present |
| 1950 |
! |
| 1951 |
select case(tagtmp) |
| 1952 |
case('apr_level') |
| 1953 |
allocate(level(isize(iarr)),massfac(isize(iarr))) |
| 1954 |
read(iunit,end=33,iostat=ierr) level |
| 1955 |
! m = m/2**(level-1) |
| 1956 |
massfac(1:isize(iarr)) = 1./2**(level(1:isize(iarr))-1) |
| 1957 |
if (iblock==1) print "(a,i2)",' :: '//trim(tagtmp)//' max level = ',maxval(level) |
| 1958 |
deallocate(level) |
| 1959 |
case default |
| 1960 |
read(iunit,end=33,iostat=ierr) |
| 1961 |
end select |
| 1962 |
enddo |
| 1963 |
! |
| 1964 |
!--real arrays |
| 1965 |
! |
| 1966 |
if (iarr==2) then |
| 1967 |
!--read sink particles from phantom dumps |
| 1968 |
if (phantomdump .and. iarr==2 .and. isize(iarr) > 0) then |
| 1969 |
if (nreal(iarr) < 5) then |
| 1970 |
print "(a)",'ERROR: not enough arrays written for sink particles in phantom dump' |
| 1971 |
nskip = nreal(iarr) |
| 1972 |
else |
| 1973 |
! skip integer arrays |
| 1974 |
nskip = nint(iarr) |
| 1975 |
do i=1,nskip |
| 1976 |
if (tagged) read(iunit,end=33,iostat=ierr) ! skip tags |
| 1977 |
read(iunit,end=33,iostat=ierr) |
| 1978 |
enddo |
| 1979 |
! set type of sink particles = -3 initially |
| 1980 |
if (debug) print*,'DEBUG: denoting ',npart,'->',npart+isize(iarr),' as sink particles' |
| 1981 |
iphase(npart+1:npart+isize(iarr)) = -3 |
| 1982 |
! |
| 1983 |
! make sure label assignment is updated for map_sink_property_to_column |
| 1984 |
! |
| 1985 |
call set_labels_sphNG() |
| 1986 |
! |
| 1987 |
! read real*4 and real*8 arrays |
| 1988 |
! |
| 1989 |
ilocvx = nreal(iarr)-2 ! velocity is always last 3 numbers for phantom sinks |
| 1990 |
if (doubleprec) then |
| 1991 |
!--convert default real to single precision where necessary |
| 1992 |
if (debug) print*,'DEBUG: reading sink data, converting from double precision ',isize(iarr) |
| 1993 |
if (allocated(dattemp)) deallocate(dattemp) |
| 1994 |
allocate(dattemp(isize(iarr)),stat=ierr) |
| 1995 |
if (ierr /= 0) then |
| 1996 |
print "(a)",'ERROR in memory allocation' |
| 1997 |
return |
| 1998 |
endif |
| 1999 |
tagtmp = '' |
| 2000 |
do k=1,nreal(iarr) |
| 2001 |
if (tagged) read(iunit,end=33,iostat=ierr) tagtmp |
| 2002 |
if (debug) print*,'DEBUG: reading sink array ',k,isize(iarr),' tag = ',trim(tagtmp) |
| 2003 |
read(iunit,end=33,iostat=ierr) dattemp(1:isize(iarr)) |
| 2004 |
if (ierr /= 0) print*,' ERROR during read of sink particle data, array ',k |
| 2005 |
|
| 2006 |
iloc = map_sink_property_to_column(k,ilocvx,size(dat(1,:,j))) |
| 2007 |
if (iloc > 0) then |
| 2008 |
do i=1,isize(iarr) |
| 2009 |
dat(npart+i,iloc,j) = real(dattemp(i)) |
| 2010 |
!if (debug) print*,'sink ',i,' col = '//tagtmp//' data = ',dat(npart+i,iloc,j),npart+i,iloc,j,ilocvx,ivx |
| 2011 |
enddo |
| 2012 |
elseif (trim(tagtmp)=='hsoft' .and. ih > 0) then |
| 2013 |
do i=1,isize(iarr) |
| 2014 |
if (abs(dat(npart+i,ih,j)) < tiny(0.)) then |
| 2015 |
dat(npart+i,ih,j) = real(dattemp(i)) |
| 2016 |
if (i == 1) print*,'zero accretion radius: taking sink particle radius from softening length' |
| 2017 |
endif |
| 2018 |
enddo |
| 2019 |
else |
| 2020 |
if (debug) print*,'DEBUG: skipping sink particle array ',k |
| 2021 |
endif |
| 2022 |
enddo |
| 2023 |
else |
| 2024 |
if (debug) print*,'DEBUG: reading sink data, converting from single precision ',isize(iarr) |
| 2025 |
if (allocated(dattempsingle)) deallocate(dattempsingle) |
| 2026 |
allocate(dattempsingle(isize(iarr)),stat=ierr) |
| 2027 |
if (ierr /= 0) then |
| 2028 |
print "(a)",'ERROR in memory allocation' |
| 2029 |
return |
| 2030 |
endif |
| 2031 |
do k=1,nreal(iarr) |
| 2032 |
if (tagged) read(iunit,end=33,iostat=ierr) tagtmp |
| 2033 |
if (debug) print*,'DEBUG: reading sink array ',k,isize(iarr),' tag = ',trim(tagtmp) |
| 2034 |
read(iunit,end=33,iostat=ierr) dattempsingle(1:isize(iarr)) |
| 2035 |
if (ierr /= 0) print*,' ERROR during read of sink particle data, array ',k |
| 2036 |
|
| 2037 |
iloc = map_sink_property_to_column(k,ilocvx,size(dat(1,:,j))) |
| 2038 |
if (iloc > 0) then |
| 2039 |
do i=1,isize(iarr) |
| 2040 |
dat(npart+i,iloc,j) = real(dattempsingle(i)) |
| 2041 |
enddo |
| 2042 |
elseif (trim(tagtmp)=='hsoft' .and. ih > 0) then |
| 2043 |
do i=1,isize(iarr) |
| 2044 |
if (abs(dat(npart+i,ih,j)) < tiny(0.)) then |
| 2045 |
dat(npart+i,ih,j) = real(dattempsingle(i)) |
| 2046 |
if (i == 1) print*,'zero accretion radius: taking sink particle radius from softening length' |
| 2047 |
endif |
| 2048 |
enddo |
| 2049 |
else |
| 2050 |
if (debug) print*,'DEBUG: skipping sink particle array ',k |
| 2051 |
endif |
| 2052 |
enddo |
| 2053 |
endif |
| 2054 |
! PSEUDO-remove accreted sinks |
| 2055 |
call set_sink_merged(npart+1,int(npart+isize(iarr)),ih,ipmass,dat(:,:,j)) |
| 2056 |
! DEFINE density on sink particles (needed for opacity rendering) |
| 2057 |
if (required(irho)) call set_sink_density(npart+1,int(npart+isize(iarr)),ih,ipmass,irho,dat(:,:,j)) |
| 2058 |
npart = npart + isize(iarr) |
| 2059 |
endif |
| 2060 |
elseif (smalldump .and. iarr==2 .and. allocated(listpm)) then |
| 2061 |
!--for sphNG, read sink particle masses from block 2 for small dumps |
| 2062 |
if (nreal(iarr) < 1) then |
| 2063 |
if (isize(iarr) > 0) print "(a)",'ERROR: sink masses not present in small dump' |
| 2064 |
nskip = nreal(iarr) + nreal4(iarr) + nreal8(iarr) |
| 2065 |
else |
| 2066 |
if (doubleprec) then |
| 2067 |
!--convert default real to single precision where necessary |
| 2068 |
if (allocated(dattemp)) deallocate(dattemp) |
| 2069 |
allocate(dattemp(isize(iarr)),stat=ierr) |
| 2070 |
if (ierr /=0) print "(a)",'ERROR in memory allocation' |
| 2071 |
if (tagged) read(iunit,end=33,iostat=ierr) ! skip tags |
| 2072 |
read(iunit,end=33,iostat=ierr) dattemp(1:isize(iarr)) |
| 2073 |
if (nptmass /= isize(iarr)) print "(a)",'ERROR: nptmass /= block size' |
| 2074 |
if (ipmass > 0) then |
| 2075 |
do i=1,isize(iarr) |
| 2076 |
dat(listpm(iptmass1+i-1),ipmass,j) = real(dattemp(i)) |
| 2077 |
enddo |
| 2078 |
else |
| 2079 |
print*,'WARNING: sink particle masses not read because no mass array allocated' |
| 2080 |
endif |
| 2081 |
else |
| 2082 |
!--convert default real to double precision where necessary |
| 2083 |
if (allocated(dattempsingle)) deallocate(dattempsingle) |
| 2084 |
allocate(dattempsingle(isize(iarr)),stat=ierr) |
| 2085 |
if (ierr /=0) print "(a)",'ERROR in memory allocation' |
| 2086 |
if (tagged) read(iunit,end=33,iostat=ierr) ! skip tags |
| 2087 |
read(iunit,end=33,iostat=ierr) dattempsingle(1:isize(iarr)) |
| 2088 |
if (nptmass /= isize(iarr)) print "(a)",'ERROR: nptmass /= block size' |
| 2089 |
if (ipmass > 0) then |
| 2090 |
do i=1,isize(iarr) |
| 2091 |
dat(listpm(iptmass1+i-1),ipmass,j) = real(dattempsingle(i)) |
| 2092 |
enddo |
| 2093 |
else |
| 2094 |
print*,'WARNING: sink particle masses not read because no mass array allocated' |
| 2095 |
endif |
| 2096 |
endif |
| 2097 |
nskip = nreal(iarr) - 1 + nreal4(iarr) + nreal8(iarr) |
| 2098 |
endif |
| 2099 |
else |
| 2100 |
!--for other blocks, skip real arrays if size different |
| 2101 |
nskip = nreal(iarr) + nreal4(iarr) + nreal8(iarr) |
| 2102 |
endif |
| 2103 |
do i=1,nskip |
| 2104 |
if (tagged) read(iunit,end=33,iostat=ierr) ! skip tags |
| 2105 |
read(iunit,end=33,iostat=ierr) |
| 2106 |
enddo |
| 2107 |
! deallocate dattempsingle |
| 2108 |
if (allocated(dattempsingle)) deallocate(dattempsingle) |
| 2109 |
|
| 2110 |
elseif (isize(iarr)==isize(1)) then |
| 2111 |
! |
| 2112 |
!--read all real arrays defined on all the particles (same size arrays as block 1) |
| 2113 |
! |
| 2114 |
if ((doubleprec.and.nreal(iarr) > 0).or.nreal8(iarr) > 0) then |
| 2115 |
if (allocated(dattemp)) deallocate(dattemp) |
| 2116 |
allocate(dattemp(isize(iarr)),stat=ierr) |
| 2117 |
if (ierr /=0) print "(a)",'ERROR in memory allocation (read_data_sphNG: dattemp)' |
| 2118 |
elseif (nreal(iarr) > 0 .or. nreal8(iarr) > 0) then |
| 2119 |
if (allocated(dattempsingle)) deallocate(dattempsingle) |
| 2120 |
allocate(dattempsingle(isize(iarr)),stat=ierr) |
| 2121 |
if (ierr /=0) print "(a)",'ERROR in memory allocation (read_data_sphNG: dattempsingle)' |
| 2122 |
endif |
| 2123 |
! default reals may need converting |
| 2124 |
do i=1,nreal(iarr) |
| 2125 |
tagtmp = '' |
| 2126 |
if (tagged) read(iunit,end=33,iostat=ierr) tagtmp |
| 2127 |
icolumn = assign_column(tagtmp,iarr,i,6,imaxcolumnread,idustarr,ncolstep) |
| 2128 |
if (tagged) tagarr(icolumn) = tagtmp |
| 2129 |
! force data read if label matches one of the required columns |
| 2130 |
if (.not.required(icolumn)) then |
| 2131 |
if (match_tag(labelreq(1:nreq),tagtmp) > 0) then |
| 2132 |
print "(1x,a,i2)",'-> found '//trim(tagtmp)//' in column ',icolumn |
| 2133 |
required(icolumn) = .true. |
| 2134 |
endif |
| 2135 |
endif |
| 2136 |
|
| 2137 |
if (debug) print*,' reading real to col:',icolumn,' tag = ',trim(tagtmp), ' required = ',required(icolumn) |
| 2138 |
if (required(icolumn)) then |
| 2139 |
if (doubleprec) then |
| 2140 |
read(iunit,end=33,iostat=ierr) dattemp(1:isize(iarr)) |
| 2141 |
dat(i1:i2,icolumn,j) = real(dattemp(1:isize(iarr))) |
| 2142 |
else |
| 2143 |
read(iunit,end=33,iostat=ierr) dattempsingle(1:isize(iarr)) |
| 2144 |
dat(i1:i2,icolumn,j) = real(dattempsingle(1:isize(iarr))) |
| 2145 |
endif |
| 2146 |
else |
| 2147 |
read(iunit,end=33,iostat=ierr) |
| 2148 |
endif |
| 2149 |
enddo |
| 2150 |
! |
| 2151 |
! set masses for equal mass particles (not dumped in small dump or in phantom) |
| 2152 |
! |
| 2153 |
if (((smalldump.and.nreal(1) < ipmass).or.phantomdump).and. iarr==1) then |
| 2154 |
if (any(abs(masstype(:,j)) > tiny(masstype))) then |
| 2155 |
icolumn = ipmass |
| 2156 |
if (required(ipmass) .and. ipmass > 0) then |
| 2157 |
if (phantomdump) then |
| 2158 |
dat(i1:i2,ipmass,j) = masstype(itypemap_phantom(iphase(i1:i2)),j) |
| 2159 |
if (allocated(massfac)) then |
| 2160 |
dat(i1:i2,ipmass,j) = dat(i1:i2,ipmass,j)*massfac(1:isize(iarr)) |
| 2161 |
deallocate(massfac) |
| 2162 |
endif |
| 2163 |
else |
| 2164 |
where (iphase(i1:i2)==0) dat(i1:i2,icolumn,j) = masstype(1,j) |
| 2165 |
endif |
| 2166 |
endif |
| 2167 |
!--dust mass for phantom particles |
| 2168 |
if (phantomdump .and. npartoftypei(itypemap_dust_phantom) > 0 .and. ipmass > 0) then |
| 2169 |
print*,'dust particle mass = ',masstype(itypemap_dust_phantom,j),& |
| 2170 |
' ratio m_dust/m_gas = ',masstype(itypemap_dust_phantom,j)/masstype(1,j) |
| 2171 |
endif |
| 2172 |
if (debug) print*,'mass ',icolumn |
| 2173 |
elseif (phantomdump .and. npartoftypei(1) > 0) then |
| 2174 |
print*,' ERROR: particle mass zero in Phantom dump file!' |
| 2175 |
endif |
| 2176 |
endif |
| 2177 |
! |
| 2178 |
! real4 arrays (may need converting if splash is compiled in double precision) |
| 2179 |
! |
| 2180 |
if (nreal4(iarr) > 0 .and. kind(dat)==doub_prec) then |
| 2181 |
if (allocated(dattempsingle)) deallocate(dattempsingle) |
| 2182 |
allocate(dattempsingle(isize(iarr)),stat=ierr) |
| 2183 |
if (ierr /=0) print "(a)",'ERROR in memory allocation (read_data_sphNG: dattempsingle)' |
| 2184 |
endif |
| 2185 |
|
| 2186 |
if (debug) print*,'DEBUG: SIZE of dattempsingle',size(dattempsingle) |
| 2187 |
! real4s may need converting |
| 2188 |
imaxcolumnread = max(imaxcolumnread,icolumn) |
| 2189 |
if ((nreal(iarr)+nreal4(iarr)) > 6) imaxcolumnread = max(imaxcolumnread,6) |
| 2190 |
|
| 2191 |
do i=1,nreal4(iarr) |
| 2192 |
tagtmp = '' |
| 2193 |
if (tagged) read(iunit,end=33,iostat=ierr) tagtmp |
| 2194 |
icolumn = assign_column(tagtmp,iarr,i,4,imaxcolumnread,idustarr,ncolstep) |
| 2195 |
if (debug) print*,'reading real4 to col:',icolumn,' tag = ',trim(tagtmp),' required = ',required(icolumn) |
| 2196 |
if (tagged) tagarr(icolumn) = tagtmp |
| 2197 |
|
| 2198 |
if (phantomdump .and. icolumn==ih) required(ih) = .true. ! h always required for density |
| 2199 |
|
| 2200 |
if (required(icolumn)) then |
| 2201 |
if (allocated(dattempsingle)) then |
| 2202 |
read(iunit,end=33,iostat=ierr) dattempsingle(1:isize(iarr)) |
| 2203 |
dat(i1:i2,icolumn,j) = real(dattempsingle(1:isize(iarr))) |
| 2204 |
else |
| 2205 |
read(iunit,end=33,iostat=ierr) dat(i1:i2,icolumn,j) |
| 2206 |
endif |
| 2207 |
else |
| 2208 |
read(iunit,end=33,iostat=ierr) |
| 2209 |
endif |
| 2210 |
!--construct density for phantom dumps based on h, hfact and particle mass |
| 2211 |
if (phantomdump .and. icolumn==ih) then |
| 2212 |
icolumn = irho ! density |
| 2213 |
call get_rho_from_h(i1,i2,ih,ipmass,irho,required,npartoftype(:,j),& |
| 2214 |
masstype(:,j),hfact,dat(:,:,j),iphase,nkilled) |
| 2215 |
endif |
| 2216 |
enddo |
| 2217 |
! real 8's need converting |
| 2218 |
do i=1,nreal8(iarr) |
| 2219 |
tagtmp = '' |
| 2220 |
if (tagged) read(iunit,end=33,iostat=ierr) tagtmp |
| 2221 |
icolumn = assign_column(tagtmp,iarr,i,8,imaxcolumnread,idustarr,ncolstep) |
| 2222 |
if (debug) print*,'reading real8 to col:',icolumn,' tag = ',trim(tagtmp),' required = ',required(icolumn) |
| 2223 |
if (tagged) tagarr(icolumn) = tagtmp |
| 2224 |
if (required(icolumn)) then |
| 2225 |
read(iunit,end=33,iostat=ierr) dattemp(1:isize(iarr)) |
| 2226 |
dat(i1:i2,icolumn,j) = real(dattemp(1:isize(iarr))) |
| 2227 |
else |
| 2228 |
read(iunit,end=33,iostat=ierr) |
| 2229 |
endif |
| 2230 |
enddo |
| 2231 |
endif |
| 2232 |
enddo ! over array sizes |
| 2233 |
enddo over_MPIblocks |
| 2234 |
! |
| 2235 |
!--reached end of file (during data read) |
| 2236 |
! |
| 2237 |
goto 34 |
| 2238 |
33 continue |
| 2239 |
print "(/,1x,a,/)",'*** WARNING: END OF FILE DURING READ ***' |
| 2240 |
print*,'Press any key to continue (but there is likely something wrong with the file...)' |
| 2241 |
read* |
| 2242 |
34 continue |
| 2243 |
|
| 2244 |
call set_labels_sphNG |
| 2245 |
! |
| 2246 |
!--emit warning if we find particles with h = 0 |
| 2247 |
! |
| 2248 |
if (nkilled > 0) print*,'WARNING: got ',nkilled,' dead (not accreted) particles, should not happen' |
| 2249 |
! |
| 2250 |
!--read .divv file for phantom dumps |
| 2251 |
! |
| 2252 |
if (phantomdump .and. idivvxcol /= 0 .and. any(required(idivvxcol:icurlvzcol))) then |
| 2253 |
print "(a)",' reading divv from '//trim(dumpfile)//'.divv' |
| 2254 |
open(unit=66,file=trim(dumpfile)//'.divv',form='unformatted',status='old',iostat=ierr) |
| 2255 |
if (ierr /= 0) then |
| 2256 |
print "(a)",' ERROR opening '//trim(dumpfile)//'.divv' |
| 2257 |
else |
| 2258 |
read(66,iostat=ierr) dat(1:ntotal,idivvxcol,j) |
| 2259 |
if (ierr /= 0) print "(a)",' WARNING: ERRORS reading divv from file' |
| 2260 |
if (any(required(icurlvxcol:icurlvzcol))) then |
| 2261 |
read(66,iostat=ierr) dat(1:ntotal,icurlvxcol,j) |
| 2262 |
read(66,iostat=ierr) dat(1:ntotal,icurlvycol,j) |
| 2263 |
read(66,iostat=ierr) dat(1:ntotal,icurlvzcol,j) |
| 2264 |
endif |
| 2265 |
if (ierr /= 0) print "(a)",' WARNING: ERRORS reading curlv from file' |
| 2266 |
close(66) |
| 2267 |
endif |
| 2268 |
endif |
| 2269 |
|
| 2270 |
if (icomp_col_start > 0 .and. any(required(icomp_col_start:icomp_col_start+ncomp))) then |
| 2271 |
if (allocated(iorig) .and. .not.got_iorig) deallocate(iorig) ! did not find iorig in dump |
| 2272 |
call read_composition(compfile,ntotal,dat(:,:,j),icomp_col_start,ncomp,iorig) |
| 2273 |
endif |
| 2274 |
! |
| 2275 |
!--calculate the temperature from density and internal energy (using physical units) |
| 2276 |
! |
| 2277 |
unit_dens = umass/(udist**3) |
| 2278 |
! |
| 2279 |
!--use primitive density for relativistic code |
| 2280 |
! |
| 2281 |
idenscol = irho |
| 2282 |
if (irhorestframe > 0) idenscol = irhorestframe |
| 2283 |
|
| 2284 |
if (get_temperature .and. itempcol > 0 .and. required(itempcol)) then |
| 2285 |
unit_ergg = (udist/utime)**2 |
| 2286 |
dat(1:ntotal,itempcol,j) = get_temp_from_u(dat(1:ntotal,idenscol,j)*unit_dens,dat(1:ntotal,iutherm,j)*unit_ergg) !irho = density |
| 2287 |
endif |
| 2288 |
if (get_kappa .and. ikappa > 0 .and. required(ikappa) .and. itemp > 0) then |
| 2289 |
write(*,"(1x,a,3(f5.2,1x))",advance='no') 'X,Y,Z = ',Xfrac,Yfrac,1.-Xfrac-Yfrac |
| 2290 |
if (get_kappa_tot) then |
| 2291 |
write(*,*) ' (opacity uses electron scattering, Kramers and H-)' |
| 2292 |
else |
| 2293 |
write(*,*) ' (electron scattering opacity only)' |
| 2294 |
endif |
| 2295 |
dat(1:ntotal,ikappa,j) = get_opacity(dat(1:ntotal,idenscol,j)*unit_dens,& |
| 2296 |
dat(1:ntotal,itemp,j)*1.d0,Xfrac,Yfrac,get_kappa_tot) |
| 2297 |
endif |
| 2298 |
if (get_ionfrac .and. iHIIcol > 0 .and. iHeIIcol > 0 .and. iHeIIIcol > 0& |
| 2299 |
.and. any(required(iHIIcol:iHeIIIcol))) then |
| 2300 |
do i=1,ntotal |
| 2301 |
call ionisation_fraction(real(dat(i,idenscol,j)*unit_dens),dat(i,itemp,j),& |
| 2302 |
real(Xfrac),real(Yfrac),xHIi,xHIIi,xHeIi,xHeIIi,xHeIIIi,nei) |
| 2303 |
dat(i,iHIIcol,j)=xHIIi |
| 2304 |
dat(i,iHeIIcol,j)=xHeIIi |
| 2305 |
dat(i,iHeIIIcol,j)=xHeIIIi |
| 2306 |
enddo |
| 2307 |
endif |
| 2308 |
|
| 2309 |
!--set flag to indicate that only part of this file has been read |
| 2310 |
if (.not.all(required(1:ncolstep))) ipartialread = .true. |
| 2311 |
|
| 2312 |
nptmassi = 0 |
| 2313 |
nunknown = 0 |
| 2314 |
ngas = 0 |
| 2315 |
ndust = 0 |
| 2316 |
nstar = 0 |
| 2317 |
!--can only do this loop if we have read the iphase array |
| 2318 |
iphasealloc: if (allocated(iphase)) then |
| 2319 |
! |
| 2320 |
!--sanity check the iphase array |
| 2321 |
! |
| 2322 |
if (gotiphase) call check_iphase_matches_npartoftype(1,npart,iphase,npartoftype(:,j),phantomdump) |
| 2323 |
! |
| 2324 |
!--translate iphase into particle types (mixed type storage) |
| 2325 |
! |
| 2326 |
if (size(iamtype(:,j)) > 1) then |
| 2327 |
if (phantomdump) then |
| 2328 |
! |
| 2329 |
!--phantom: translate iphase to splash types |
| 2330 |
! |
| 2331 |
do i=1,npart |
| 2332 |
itype = itypemap_phantom(iphase(i)) |
| 2333 |
iamtype(i,j) = itype |
| 2334 |
if (ih > 0 .and. required(ih)) then |
| 2335 |
if (dat(i,ih,j) <= 0. .and. itype /= itypemap_sink_phantom) iamtype(i,j) = itypemap_unknown_phantom |
| 2336 |
endif |
| 2337 |
enddo |
| 2338 |
else |
| 2339 |
! |
| 2340 |
!--sphNG: translate iphase to splash types |
| 2341 |
! |
| 2342 |
do i=1,npart |
| 2343 |
itype = itypemap_sphNG(iphase(i)) |
| 2344 |
iamtype(i,j) = itype |
| 2345 |
select case(itype) |
| 2346 |
case(1) |
| 2347 |
ngas = ngas + 1 |
| 2348 |
case(2) |
| 2349 |
ndust = ndust + 1 |
| 2350 |
case(4) |
| 2351 |
nptmassi = nptmassi + 1 |
| 2352 |
case(5) |
| 2353 |
nstar = nstar + 1 |
| 2354 |
case default |
| 2355 |
nunknown = nunknown + 1 |
| 2356 |
end select |
| 2357 |
enddo |
| 2358 |
do i=npart+1,ntotal |
| 2359 |
iamtype(i,j) = 2 |
| 2360 |
enddo |
| 2361 |
endif |
| 2362 |
!print*,'mixed types: ngas = ',ngas,nptmassi,nunknown |
| 2363 |
|
| 2364 |
elseif (any(iphase(1:ntotal) /= 0)) then |
| 2365 |
if (phantomdump) then |
| 2366 |
print*,'ERROR: low memory mode will not work correctly with phantom + multiple types' |
| 2367 |
print*,'press any key to ignore this and continue anyway (at your own risk...)' |
| 2368 |
read* |
| 2369 |
endif |
| 2370 |
! |
| 2371 |
!--place point masses after normal particles |
| 2372 |
! if not storing the iamtype array |
| 2373 |
! |
| 2374 |
print "(a)",' sorting particles by type...' |
| 2375 |
nunknown = 0 |
| 2376 |
do i=1,npart |
| 2377 |
if (iphase(i) /= 0) nunknown = nunknown + 1 |
| 2378 |
enddo |
| 2379 |
ncolcopy = min(ncolstep,maxcol) |
| 2380 |
allocate(dattemp2(nunknown,ncolcopy)) |
| 2381 |
|
| 2382 |
iphaseminthistype = 0 ! to avoid compiler warnings |
| 2383 |
iphasemaxthistype = 0 |
| 2384 |
do itype=1,3 |
| 2385 |
nthistype = 0 |
| 2386 |
ipos = 0 |
| 2387 |
select case(itype) |
| 2388 |
case(1) ! ptmass |
| 2389 |
iphaseminthistype = 1 |
| 2390 |
iphasemaxthistype = 9 |
| 2391 |
case(2) ! star |
| 2392 |
iphaseminthistype = 10 |
| 2393 |
iphasemaxthistype = huge(iphasemaxthistype) |
| 2394 |
case(3) ! unknown |
| 2395 |
iphaseminthistype = -huge(iphaseminthistype) |
| 2396 |
iphasemaxthistype = -1 |
| 2397 |
end select |
| 2398 |
|
| 2399 |
do i=1,ntotal |
| 2400 |
ipos = ipos + 1 |
| 2401 |
if (iphase(i) >= iphaseminthistype .and. iphase(i) <= iphasemaxthistype) then |
| 2402 |
nthistype = nthistype + 1 |
| 2403 |
!--save point mass information in temporary array |
| 2404 |
if (nptmassi > size(dattemp2(:,1))) stop 'error: ptmass array bounds exceeded in data read' |
| 2405 |
dattemp2(nthistype,1:ncolcopy) = dat(i,1:ncolcopy,j) |
| 2406 |
! print*,i,' removed', dat(i,1:3,j) |
| 2407 |
ipos = ipos - 1 |
| 2408 |
endif |
| 2409 |
!--shuffle dat array |
| 2410 |
if (ipos /= i .and. i < ntotal) then |
| 2411 |
! print*,'copying ',i+1,'->',ipos+1 |
| 2412 |
dat(ipos+1,1:ncolcopy,j) = dat(i+1,1:ncolcopy,j) |
| 2413 |
!--must also shuffle iphase (to be correct for other types) |
| 2414 |
iphase(ipos+1) = iphase(i+1) |
| 2415 |
endif |
| 2416 |
enddo |
| 2417 |
|
| 2418 |
!--append this type to end of dat array |
| 2419 |
do i=1,nthistype |
| 2420 |
ipos = ipos + 1 |
| 2421 |
! print*,ipos,' appended', dattemp2(i,1:3) |
| 2422 |
dat(ipos,1:ncolcopy,j) = dattemp2(i,1:ncolcopy) |
| 2423 |
!--we make iphase = 1 for point masses (could save iphase and copy across but no reason to) |
| 2424 |
iphase(ipos) = iphaseminthistype |
| 2425 |
enddo |
| 2426 |
|
| 2427 |
select case(itype) |
| 2428 |
case(1) |
| 2429 |
nptmassi = nthistype |
| 2430 |
if (nptmassi /= nptmass) print *,'WARNING: nptmass from iphase =',nptmassi,'not equal to nptmass =',nptmass |
| 2431 |
case(2) |
| 2432 |
nstar = nthistype |
| 2433 |
case(3) |
| 2434 |
nunknown = nthistype |
| 2435 |
end select |
| 2436 |
enddo |
| 2437 |
|
| 2438 |
endif |
| 2439 |
|
| 2440 |
endif iphasealloc |
| 2441 |
|
| 2442 |
call set_labels_sphNG |
| 2443 |
if (.not.phantomdump) then |
| 2444 |
if (ngas /= npart - nptmassi - ndust - nstar - nunknown) & |
| 2445 |
print*,'WARNING!!! ngas =',ngas,'but should be',npart-nptmassi-ndust-nstar-nunknown |
| 2446 |
if (ndust /= npart - nptmassi - ngas - nstar - nunknown) & |
| 2447 |
print*,'WARNING!!! ndust =',ndust,'but should be',npart-nptmassi-ngas-nstar-nunknown |
| 2448 |
npartoftype(:,j) = 0 |
| 2449 |
npartoftype(1,j) = ngas ! npart - nptmassi - ndust - nstar - nunknown |
| 2450 |
npartoftype(2,j) = ndust ! npart - nptmassi - ngas - nstar - nunknown |
| 2451 |
npartoftype(3,j) = ntotal - npart |
| 2452 |
npartoftype(4,j) = nptmassi |
| 2453 |
npartoftype(5,j) = nstar |
| 2454 |
npartoftype(6,j) = nunknown |
| 2455 |
else |
| 2456 |
if (debug) print*,' DEBUG: nunknown = ',nunknown |
| 2457 |
npartoftype(1,j) = npartoftype(1,j) - nunknown |
| 2458 |
npartoftype(itypemap_unknown_phantom,j) = npartoftype(itypemap_unknown_phantom,j) + nunknown |
| 2459 |
endif |
| 2460 |
|
| 2461 |
|
| 2462 |
! |
| 2463 |
!--reset centre of mass to zero if environment variable "SSPLASH_RESET_CM" is set, |
| 2464 |
! or reset centre to densest clump if environment variable "SSPLASH_RESET_DENSE" is set |
| 2465 |
! the latter will override the former |
| 2466 |
! (updated from n1 to npart since order is not preserved when dumping data; JHW) |
| 2467 |
icentre = 0 |
| 2468 |
if (lenvironment('SSPLASH_RESET_CM')) icentre = 1 |
| 2469 |
if (lenvironment('SSPLASH_RESET_DENSE')) icentre = 2 |
| 2470 |
if (allocated(dat) .and. npart > 0 .and. npart <= size(dat(:,1,1)) .and. icentre > 0 .and. allocated(iphase)) then |
| 2471 |
call reset_centre_of_mass(dat(1:npart,1:3,j),dat(1:npart,4,j),dat(1:npart,5,j),iphase(1:npart),npart,icentre) |
| 2472 |
endif |
| 2473 |
! |
| 2474 |
!--reset corotating frame velocities if environment variable "SSPLASH_OMEGA" is set |
| 2475 |
! |
| 2476 |
if (allocated(dat) .and. n1 > 0 .and. all(required(1:2))) then |
| 2477 |
rad_corotate = renvironment('SSPLASH_OMEGAR') |
| 2478 |
call locate_nth_particle_of_type(1,isink1,get_sink_type(ntypes),iamtype(:,j),npartoftype(:,j),ntotal) |
| 2479 |
if (rad_corotate > tiny(rad_corotate) .and. isink1 > 0) then |
| 2480 |
m1 = dat(isink1,4,j) |
| 2481 |
omega = -sqrt(m1 / rad_corotate**3) |
| 2482 |
print "(a,g8.2,a,g8.2)",' :: COROTATING FRAME at R = ',rad_corotate,' around sink particle #1, M=',m1 |
| 2483 |
else |
| 2484 |
omega = renvironment('SSPLASH_OMEGAT') |
| 2485 |
endif |
| 2486 |
if (abs(omega) > tiny(omega) .and. ndim >= 2) then |
| 2487 |
call reset_corotating_positions(n1,dat(1:n1,1:2,j),omega,time(j)) |
| 2488 |
endif |
| 2489 |
|
| 2490 |
if (.not. smalldump) then |
| 2491 |
if (abs(omega) < tiny(omega)) omega = renvironment('SSPLASH_OMEGA') |
| 2492 |
if (abs(omega) > tiny(omega) .and. ivx > 0) then |
| 2493 |
if (.not.all(required(1:2)) .or. .not.all(required(ivx:ivx+1))) then |
| 2494 |
print*,' ERROR subtracting corotating frame with partial data read' |
| 2495 |
else |
| 2496 |
call reset_corotating_velocities(n1,dat(1:n1,1:2,j),dat(1:n1,ivx:ivx+1,j),omega) |
| 2497 |
endif |
| 2498 |
endif |
| 2499 |
endif |
| 2500 |
endif |
| 2501 |
|
| 2502 |
if (iverbose > 0) call print_types(npartoftype(:,j),labeltype) |
| 2503 |
|
| 2504 |
close(15) |
| 2505 |
|
| 2506 |
if (allocated(dattemp)) deallocate(dattemp) |
| 2507 |
if (allocated(dattempsingle)) deallocate(dattempsingle) |
| 2508 |
if (allocated(dattemp2)) deallocate(dattemp2) |
| 2509 |
if (allocated(iphase)) deallocate(iphase) |
| 2510 |
if (allocated(listpm)) deallocate(listpm) |
| 2511 |
|
| 2512 |
if (debug) print*,' finished data read, npart = ',npart, ntotal, npartoftype(1:ntypes,j) |
| 2513 |
|
| 2514 |
return |
| 2515 |
|
| 2516 |
contains |
| 2517 |
|
| 2518 |
! |
| 2519 |
!--reset centre of mass to zero |
| 2520 |
! |
| 2521 |
subroutine reset_centre_of_mass(xyz,pmass,h,iphase,np,icentre) |
| 2522 |
implicit none |
| 2523 |
integer, intent(in) :: np,icentre |
| 2524 |
real, dimension(np,3), intent(inout) :: xyz |
| 2525 |
real, dimension(np), intent(in) :: h,pmass |
| 2526 |
integer(kind=int1), dimension(np), intent(in) :: iphase |
| 2527 |
real :: masstot,pmassi,minh |
| 2528 |
real, dimension(3) :: xcm |
| 2529 |
integer :: i,ctr |
| 2530 |
! |
| 2531 |
!--get centre of mass |
| 2532 |
! |
| 2533 |
xcm(:) = 0. |
| 2534 |
masstot = 0. |
| 2535 |
minh = huge(minh) |
| 2536 |
do i=1,np |
| 2537 |
if (iphase(i) >= 0) then |
| 2538 |
pmassi = pmass(i) |
| 2539 |
masstot = masstot + pmass(i) |
| 2540 |
where (required(1:3)) xcm(:) = xcm(:) + pmassi*xyz(i,:) |
| 2541 |
minh = min(h(i),minh) |
| 2542 |
endif |
| 2543 |
enddo |
| 2544 |
! |
| 2545 |
!--if requested, find the location of the densest clump |
| 2546 |
if (icentre==2) then |
| 2547 |
xcm(:) = 0. |
| 2548 |
masstot = 0. |
| 2549 |
ctr = 0 |
| 2550 |
do i=1,np |
| 2551 |
if (iphase(i) >= 0 .and. h(i) < minh*1.05) then |
| 2552 |
ctr = ctr + 1 |
| 2553 |
pmassi = pmass(i) |
| 2554 |
masstot = masstot + pmass(i) |
| 2555 |
where (required(1:3)) xcm(:) = xcm(:) + pmassi*xyz(i,:) |
| 2556 |
endif |
| 2557 |
enddo |
| 2558 |
endif |
| 2559 |
|
| 2560 |
xcm(:) = xcm(:)/masstot |
| 2561 |
if (icentre==1) then |
| 2562 |
print*,' RESETTING CENTRE OF MASS (',pack(xcm,required(1:3)),') TO ZERO ' |
| 2563 |
elseif (icentre==2) then |
| 2564 |
print*,' RESETTING CENTRE OF DENSEST CLUMP (',pack(xcm,required(1:3)),') TO ZERO using ',ctr,' particles' |
| 2565 |
endif |
| 2566 |
if (required(1)) xyz(1:np,1) = xyz(1:np,1) - xcm(1) |
| 2567 |
if (required(2)) xyz(1:np,2) = xyz(1:np,2) - xcm(2) |
| 2568 |
if (required(3)) xyz(1:np,3) = xyz(1:np,3) - xcm(3) |
| 2569 |
|
| 2570 |
return |
| 2571 |
end subroutine reset_centre_of_mass |
| 2572 |
|
| 2573 |
subroutine reset_corotating_velocities(np,xy,velxy,omeg) |
| 2574 |
integer, intent(in) :: np |
| 2575 |
real, dimension(np,2), intent(in) :: xy |
| 2576 |
real, dimension(np,2), intent(inout) :: velxy |
| 2577 |
real, intent(in) :: omeg |
| 2578 |
integer :: ip |
| 2579 |
|
| 2580 |
print*,'SUBTRACTING COROTATING VELOCITIES, OMEGA = ',omeg |
| 2581 |
do ip=1,np |
| 2582 |
velxy(ip,1) = velxy(ip,1) + xy(ip,2)*omeg |
| 2583 |
enddo |
| 2584 |
do ip=1,np |
| 2585 |
velxy(ip,2) = velxy(ip,2) - xy(ip,1)*omeg |
| 2586 |
enddo |
| 2587 |
|
| 2588 |
return |
| 2589 |
end subroutine reset_corotating_velocities |
| 2590 |
|
| 2591 |
subroutine reset_corotating_positions(np,xy,omeg,t) |
| 2592 |
integer, intent(in) :: np |
| 2593 |
real, dimension(np,2), intent(inout) :: xy |
| 2594 |
real, intent(in) :: omeg,t |
| 2595 |
real :: phii,phinew,r |
| 2596 |
integer :: ip |
| 2597 |
|
| 2598 |
print*,'SUBTRACTING COROTATING POSITIONS, OMEGA = ',omeg,' t = ',t |
| 2599 |
!$omp parallel default(none) & |
| 2600 |
!$omp shared(xy,np) & |
| 2601 |
!$omp firstprivate(omeg,t) & |
| 2602 |
!$omp private(ip,r,phii,phinew) |
| 2603 |
!$omp do |
| 2604 |
do ip=1,np |
| 2605 |
r = sqrt(xy(ip,1)**2 + xy(ip,2)**2) |
| 2606 |
phii = atan2(xy(ip,2),xy(ip,1)) |
| 2607 |
phinew = phii + omeg*t |
| 2608 |
xy(ip,1) = r*cos(phinew) |
| 2609 |
xy(ip,2) = r*sin(phinew) |
| 2610 |
enddo |
| 2611 |
!$omp enddo |
| 2612 |
!$omp end parallel |
| 2613 |
|
| 2614 |
return |
| 2615 |
end subroutine reset_corotating_positions |
| 2616 |
|
| 2617 |
end subroutine read_data_sphNG |
| 2618 |
|
| 2619 |
!------------------------------------------------------------ |
| 2620 |
! set labels for each column of data |
| 2621 |
!------------------------------------------------------------ |
| 2622 |
subroutine set_labels_sphNG |
| 2623 |
use labels, only:label,unitslabel=>unitslabel_default,& |
| 2624 |
labelzintegration=>labelzintegration_default,labeltype,labelvec,iamvec, & |
| 2625 |
ix,ipmass,irho,ih,iutherm,ipr,ivx,iBfirst,idivB,iJfirst,icv,iradenergy,& |
| 2626 |
idustfrac,ideltav,idustfracsum,ideltavsum,igrainsize,igraindens,iradFx, & |
| 2627 |
ivrel,make_vector_label,get_label_grain_size,itemp,ikappa,ipmomx,irhorestframe |
| 2628 |
use params |
| 2629 |
use settings_data, only:ndim,ndimV,ntypes,ncolumns,UseTypeInRenderings,debugmode |
| 2630 |
use geometry, only:labelcoord |
| 2631 |
use settings_units, only:units=>units_default,unitzintegration=>unitzintegration_default,& |
| 2632 |
get_nearest_length_unit,get_nearest_time_unit,& |
| 2633 |
get_nearest_mass_unit,get_nearest_velocity_unit |
| 2634 |
use sphNGread |
| 2635 |
use asciiutils, only:lcase,make_tags_unique,match_tag |
| 2636 |
use system_utils, only:lenvironment,get_environment_or_flag |
| 2637 |
integer :: i,j,idustlast |
| 2638 |
real(doub_prec) :: unitx,unitvel,unitmass |
| 2639 |
character(len=20) :: string,unitlabelx,unitlabelv |
| 2640 |
character(len=20) :: deltav_string |
| 2641 |
|
| 2642 |
if (ndim <= 0 .or. ndim > 3) then |
| 2643 |
print*,'*** ERROR: ndim = ',ndim,' in set_labels_sphNG ***' |
| 2644 |
return |
| 2645 |
endif |
| 2646 |
if (ndimV <= 0 .or. ndimV > 3) then |
| 2647 |
print*,'*** ERROR: ndimV = ',ndimV,' in set_labels_sphNG ***' |
| 2648 |
return |
| 2649 |
endif |
| 2650 |
!--all formats read the following columns |
| 2651 |
do i=1,ndim |
| 2652 |
ix(i) = i |
| 2653 |
enddo |
| 2654 |
if (igotmass) then |
| 2655 |
ipmass = 4 ! particle mass |
| 2656 |
ih = 5 ! smoothing length |
| 2657 |
else |
| 2658 |
ipmass = 0 |
| 2659 |
ih = 4 ! smoothing length |
| 2660 |
endif |
| 2661 |
irho = ih + 1 ! density |
| 2662 |
iutherm = 0 |
| 2663 |
idustfrac = 0 |
| 2664 |
|
| 2665 |
! |
| 2666 |
!--translate array tags into column labels, where necessary |
| 2667 |
! |
| 2668 |
if (tagged) then |
| 2669 |
do i=1,ncolumns |
| 2670 |
label(i) = tagarr(i) |
| 2671 |
select case(trim(tagarr(i))) |
| 2672 |
case('m') |
| 2673 |
ipmass = i |
| 2674 |
case('h') |
| 2675 |
ih = i |
| 2676 |
case('rho') |
| 2677 |
irho = i |
| 2678 |
case('vx') |
| 2679 |
ivx = i |
| 2680 |
case('pressure') |
| 2681 |
ipr = i |
| 2682 |
case('u') |
| 2683 |
iutherm = i |
| 2684 |
case('divv') |
| 2685 |
idivvcol = i |
| 2686 |
units(i) = 1./utime |
| 2687 |
unitslabel(i) = ' [1/s]' |
| 2688 |
case('divvx') |
| 2689 |
idivvxcol = i |
| 2690 |
units(i) = 1./utime |
| 2691 |
unitslabel(i) = ' [1/s]' |
| 2692 |
case('poten') |
| 2693 |
units(i) = umass*(udist/utime)**2 |
| 2694 |
unitslabel(i) = ' [erg]' |
| 2695 |
case('dt') |
| 2696 |
units(i) = utime |
| 2697 |
unitslabel(i) = ' [s]' |
| 2698 |
case('curlvx') |
| 2699 |
icurlvxcol = i |
| 2700 |
case('curlvy') |
| 2701 |
icurlvycol = i |
| 2702 |
case('curlvz') |
| 2703 |
icurlvzcol = i |
| 2704 |
case('Bx') |
| 2705 |
iBfirst = i |
| 2706 |
case('divB') |
| 2707 |
idivB = i |
| 2708 |
case('curlBx') |
| 2709 |
iJfirst = i |
| 2710 |
case('psi') |
| 2711 |
label(i) = '\psi' |
| 2712 |
units(i) = umagfd*udist/utime |
| 2713 |
unitslabel(i) = ' [G cm/s]' |
| 2714 |
case('psi/c_h') |
| 2715 |
units(i) = umagfd |
| 2716 |
unitslabel(i) = ' [G]' |
| 2717 |
case('dustfracsum') |
| 2718 |
idustfracsum = i |
| 2719 |
case('deltavsumx') |
| 2720 |
ideltavsum = i |
| 2721 |
case('deltavx') |
| 2722 |
ideltav = i |
| 2723 |
case('alpha') |
| 2724 |
label(i) = '\alpha' |
| 2725 |
case('alphaB') |
| 2726 |
label(i) = '\alpha_B' |
| 2727 |
case('EulerAlpha') |
| 2728 |
label(i) = 'Euler \alpha' |
| 2729 |
case('EulerBeta') |
| 2730 |
label(i) = 'Euler \beta' |
| 2731 |
case('EtaReal') |
| 2732 |
label(i) = '\eta_{real}' |
| 2733 |
case('EtaArtificial') |
| 2734 |
label(i) = '\eta_{art}' |
| 2735 |
case('Erad','xi') |
| 2736 |
iradenergy = i |
| 2737 |
label(i) = '\xi' |
| 2738 |
unitslabel(i) = ' [erg/g]' |
| 2739 |
units(i) = (udist/utime)**2 |
| 2740 |
case('opacity') |
| 2741 |
label(i) = 'opacity' |
| 2742 |
unitslabel(i) = ' [cm^2/g]' |
| 2743 |
units(i) = udist**2/umass |
| 2744 |
case('kappa') |
| 2745 |
unitslabel(i) = ' [cm^2/g]' |
| 2746 |
units(i) = udist**2/umass |
| 2747 |
ikappa = i |
| 2748 |
case('radFx') |
| 2749 |
iradFx = i |
| 2750 |
case('radP') |
| 2751 |
label(i) = 'radiation pressure' |
| 2752 |
unitslabel(i) = ' [g / (cm s^2)]' |
| 2753 |
units(i) = umass/(udist*utime**2) |
| 2754 |
case('EddingtonFactor','edd') |
| 2755 |
label(i) = 'Eddington Factor' |
| 2756 |
case('Cv','cv') |
| 2757 |
label(i) = 'C_v' |
| 2758 |
icv = i |
| 2759 |
units(i) = (udist/utime)**2 |
| 2760 |
unitslabel(i) = ' [erg/(g K)]' |
| 2761 |
case('h2ratio') |
| 2762 |
label(i) = 'H_2 ratio' |
| 2763 |
case('abH1q','abHIq') |
| 2764 |
label(i) = 'HI abundance' |
| 2765 |
case('abhpq') |
| 2766 |
label(i) = 'proton abundance' |
| 2767 |
case('abeq') |
| 2768 |
label(i) = 'e^- abundance' |
| 2769 |
case('abco') |
| 2770 |
label(i) = 'CO abundance' |
| 2771 |
case('eta_{OR}') |
| 2772 |
units(i:i+2) = udist**2/utime |
| 2773 |
unitslabel(i:i+2) = ' [cm^2/s]' |
| 2774 |
case('grainsize') |
| 2775 |
igrainsize = i |
| 2776 |
case('graindens') |
| 2777 |
igraindens = i |
| 2778 |
case('grainmass') |
| 2779 |
label(i) = 'grain mass' |
| 2780 |
units(i) = umass |
| 2781 |
unitslabel(i) = ' [g]' |
| 2782 |
case('csound') |
| 2783 |
label(i) = 'sound speed' |
| 2784 |
units(i) = udist/utime |
| 2785 |
unitslabel(i) = ' [cm/s]' |
| 2786 |
case('rhogas') |
| 2787 |
label(i) = '\rho_g' |
| 2788 |
units(i) = umass/udist**3 |
| 2789 |
unitslabel(i) = ' [g/cm^3]' |
| 2790 |
case('dv') |
| 2791 |
label(i) = 'dv' |
| 2792 |
units(i) = udist/utime |
| 2793 |
unitslabel(i) = ' [cm/s]' |
| 2794 |
case('temperature') |
| 2795 |
itemp = i |
| 2796 |
case('vrel') |
| 2797 |
ivrel = i |
| 2798 |
case('px') |
| 2799 |
ipmomx = i |
| 2800 |
case('dens prim') |
| 2801 |
irhorestframe = i |
| 2802 |
case default |
| 2803 |
if (debugmode) print "(a,i2)",' DEBUG: Unknown label '''//trim(tagarr(i))//''' in column ',i |
| 2804 |
label(i) = tagarr(i) |
| 2805 |
end select |
| 2806 |
enddo |
| 2807 |
else |
| 2808 |
if (smalldump .and. nhydroreal4 >= 3) iutherm = irho+1 |
| 2809 |
call guess_labels(ncolumns,iamvec,label,labelvec,istartmhd,istart_extra_real4,& |
| 2810 |
nmhd,nhydroreal4,ndimV,irho,iBfirst,ivx,iutherm,idivB,iJfirst,& |
| 2811 |
iradenergy,icv,udist,utime,units,unitslabel) |
| 2812 |
endif |
| 2813 |
|
| 2814 |
if (itemp==0 .or. itempcol > 0) itemp=itempcol ! if temperature not found in file, use computed one |
| 2815 |
|
| 2816 |
label(ix(1:ndim)) = labelcoord(1:ndim,1) |
| 2817 |
if (irho > 0) label(irho) = 'density' |
| 2818 |
if (iutherm > 0) label(iutherm) = 'u' |
| 2819 |
if (ih > 0) label(ih) = 'h ' |
| 2820 |
if (ipmass > 0) label(ipmass) = 'particle mass' |
| 2821 |
if (idivB > 0) label(idivB) = 'div B' |
| 2822 |
if (idivvxcol > 0) label(idivvxcol) = 'div vx' |
| 2823 |
if (idivvcol > 0) label(idivvcol) = 'div v' |
| 2824 |
if (itemp > 0) then |
| 2825 |
label(itemp) = 'temperature' |
| 2826 |
unitslabel(itemp) = ' [K]' |
| 2827 |
endif |
| 2828 |
if (itempcol > 0) then |
| 2829 |
if (itempcol /= itemp) label(itempcol) = 'temperature (from u)' |
| 2830 |
unitslabel(itempcol) = ' [K]' |
| 2831 |
endif |
| 2832 |
if (ikappa > 0) label(ikappa) = 'kappa' |
| 2833 |
if (iHIIcol > 0) label(iHIIcol) = 'HII fraction' |
| 2834 |
if (iHeIIcol > 0) label(iHeIIcol) = 'HeII fraction' |
| 2835 |
if (iHeIIIcol > 0) label(iHeIIIcol) = 'HeIII fraction' |
| 2836 |
if (icurlvxcol > 0 .and. icurlvycol > 0 .and. icurlvzcol > 0) then |
| 2837 |
call make_vector_label('curl v',icurlvxcol,ndimV,iamvec,labelvec,label,labelcoord(:,1)) |
| 2838 |
endif |
| 2839 |
if (ideltavsum > 0) then |
| 2840 |
! Modify the deltavsum labels to have vector subscripts |
| 2841 |
do j=1,ndimV |
| 2842 |
label(ideltavsum+j-1) = 'deltavsum'//'_'//labelcoord(j,1) |
| 2843 |
enddo |
| 2844 |
! Make N deltav labels with vector subscripts |
| 2845 |
do i = ideltavsum+ndimV,ideltav,ndimV |
| 2846 |
write(deltav_string,'(i10)') (i-ideltavsum)/ndimV |
| 2847 |
write(deltav_string,'(a)') 'deltav'//trim(adjustl(deltav_string)) |
| 2848 |
do j=1,ndimV |
| 2849 |
label(i+j-1) = trim(deltav_string)//'_'//labelcoord(j,1) |
| 2850 |
enddo |
| 2851 |
enddo |
| 2852 |
endif |
| 2853 |
! |
| 2854 |
!--set labels for vector quantities |
| 2855 |
! |
| 2856 |
call make_vector_label('v',ivx,ndimV,iamvec,labelvec,label,labelcoord(:,1)) |
| 2857 |
call make_vector_label('B',iBfirst,ndimV,iamvec,labelvec,label,labelcoord(:,1)) |
| 2858 |
call make_vector_label('J',iJfirst,ndimV,iamvec,labelvec,label,labelcoord(:,1)) |
| 2859 |
call make_vector_label('p',ipmomx,ndimV,iamvec,labelvec,label,labelcoord(:,1)) |
| 2860 |
call make_vector_label('grad E',iradFx,ndimV,iamvec,labelvec,label,labelcoord(:,1)) |
| 2861 |
! |
| 2862 |
!--ensure labels are unique by appending numbers where necessary |
| 2863 |
! |
| 2864 |
call make_tags_unique(ncolumns,label) |
| 2865 |
! |
| 2866 |
!--identify dust fraction in the case where there is only one species |
| 2867 |
! |
| 2868 |
idustfrac = match_tag(label,'dustfrac') |
| 2869 |
! |
| 2870 |
!--set units for plot data |
| 2871 |
! |
| 2872 |
call get_nearest_length_unit(udist,unitx,unitlabelx) |
| 2873 |
call get_nearest_velocity_unit(udist/utime,unitvel,unitlabelv) |
| 2874 |
if (ndim >= 3) then |
| 2875 |
units(1:3) = unitx |
| 2876 |
unitslabel(1:3) = unitlabelx |
| 2877 |
endif |
| 2878 |
if (ipmass > 0) then |
| 2879 |
call get_nearest_mass_unit(umass,unitmass,unitslabel(ipmass)) |
| 2880 |
units(ipmass) = unitmass |
| 2881 |
endif |
| 2882 |
units(ih) = unitx |
| 2883 |
unitslabel(ih) = unitlabelx |
| 2884 |
if (ivx > 0) then |
| 2885 |
units(ivx:ivx+ndimV-1) = unitvel |
| 2886 |
unitslabel(ivx:ivx+ndimV-1) = unitlabelv |
| 2887 |
endif |
| 2888 |
if (iradFx > 0) then |
| 2889 |
units(iradFx:iradFx+ndimV-1) = umass/(udist*utime)**2 |
| 2890 |
unitslabel(iradFx:iradFx+ndimV-1) = ' [erg/cm^4]' |
| 2891 |
endif |
| 2892 |
if (ipmomx > 0) then |
| 2893 |
units(ipmomx:ipmomx+ndimV-1) = unitvel |
| 2894 |
unitslabel(ipmomx:ipmomx+ndimV-1) = unitlabelv |
| 2895 |
endif |
| 2896 |
if (ideltavsum > 0) then |
| 2897 |
units(ideltavsum:ideltav+ndimV-1) = unitvel |
| 2898 |
unitslabel(ideltavsum:ideltav+ndimV-1) = unitlabelv |
| 2899 |
endif |
| 2900 |
if (ideltav > 0) then |
| 2901 |
units(ideltav:ideltav+ndimV-1) = unitvel |
| 2902 |
unitslabel(ideltav:ideltav+ndimV-1) = unitlabelv |
| 2903 |
endif |
| 2904 |
if (iutherm > 0) then |
| 2905 |
units(iutherm) = (udist/utime)**2 |
| 2906 |
unitslabel(iutherm) = ' [erg/g]' |
| 2907 |
endif |
| 2908 |
if (ipr > 0) then |
| 2909 |
units(ipr) = umass/(udist*utime**2) |
| 2910 |
unitslabel(ipr) = ' [g / (cm s^2)]' |
| 2911 |
endif |
| 2912 |
units(irho) = umass/udist**3 |
| 2913 |
unitslabel(irho) = ' [g/cm^3]' |
| 2914 |
if (iBfirst > 0) then |
| 2915 |
units(iBfirst:iBfirst+ndimV-1) = umagfd |
| 2916 |
unitslabel(iBfirst:iBfirst+ndimV-1) = ' [G]' |
| 2917 |
endif |
| 2918 |
if (igrainsize > 0) then |
| 2919 |
units(igrainsize) = udist |
| 2920 |
unitslabel(igrainsize) = ' [cm]' |
| 2921 |
endif |
| 2922 |
if (igraindens > 0) then |
| 2923 |
units(igraindens) = umass/udist**3 |
| 2924 |
unitslabel(igraindens) = ' [g/cm^3]' |
| 2925 |
endif |
| 2926 |
if (ivrel > 0) then |
| 2927 |
units(ivrel) = udist/utime/100 |
| 2928 |
unitslabel(ivrel) = ' [m/s]' |
| 2929 |
endif |
| 2930 |
if (idivB > 0) then |
| 2931 |
units(idivB:idivB+3) = umagfd/unitx |
| 2932 |
unitslabel(idivB:idivB+3) = ' [G/'//trim(unitlabelx(3:)) |
| 2933 |
endif |
| 2934 |
|
| 2935 |
!--use the following two lines for time in years |
| 2936 |
call get_environment_or_flag('SSPLASH_TIMEUNITS',string) |
| 2937 |
select case(trim(lcase(adjustl(string)))) |
| 2938 |
case('s','seconds') |
| 2939 |
units(0) = utime |
| 2940 |
unitslabel(0) = trim(string) |
| 2941 |
case('min','minutes','mins') |
| 2942 |
units(0) = utime/60.d0 |
| 2943 |
unitslabel(0) = trim(string) |
| 2944 |
case('h','hr','hrs','hours','hour') |
| 2945 |
units(0) = utime/3600.d0 |
| 2946 |
unitslabel(0) = trim(string) |
| 2947 |
case('y','yr','yrs','years','year') |
| 2948 |
units(0) = utime/3.1536d7 |
| 2949 |
unitslabel(0) = trim(string) |
| 2950 |
case('d','day','days') |
| 2951 |
units(0) = utime/(3600.d0*24.d0) |
| 2952 |
unitslabel(0) = trim(string) |
| 2953 |
case('tff','freefall','tfreefall') |
| 2954 |
!--or use these two lines for time in free-fall times |
| 2955 |
units(0) = 1./tfreefall |
| 2956 |
unitslabel(0) = ' ' |
| 2957 |
case default |
| 2958 |
if (dtmax > 0. .and. (abs(utime-1d0) > 0.d0)) then ! use interval between dumps |
| 2959 |
call get_nearest_time_unit(utime*dtmax,unitx,unitslabel(0)) |
| 2960 |
unitx = unitx/dtmax |
| 2961 |
else |
| 2962 |
call get_nearest_time_unit(utime,unitx,unitslabel(0)) |
| 2963 |
endif |
| 2964 |
units(0) = unitx ! convert to real*4 |
| 2965 |
end select |
| 2966 |
|
| 2967 |
unitzintegration = udist |
| 2968 |
labelzintegration = ' [cm]' |
| 2969 |
! |
| 2970 |
!--set labels for each particle type |
| 2971 |
! |
| 2972 |
if (phantomdump) then ! phantom |
| 2973 |
ntypes = itypemap_unknown_phantom |
| 2974 |
labeltype(1) = 'gas' |
| 2975 |
labeltype(2) = 'dust (old)' |
| 2976 |
labeltype(3) = 'sink' |
| 2977 |
labeltype(4) = 'ghost' |
| 2978 |
labeltype(5) = 'star' |
| 2979 |
labeltype(6) = 'dark matter' |
| 2980 |
labeltype(7) = 'bulge' |
| 2981 |
if (ndustlarge > 0) then |
| 2982 |
! try to label dust particles as 1cm dust, 10cm dust etc. |
| 2983 |
idustlast = min(8+ndustlarge-1,size(labeltype)-1) |
| 2984 |
if (allocated(grainsize)) then |
| 2985 |
do i=1,ndustlarge |
| 2986 |
j = 8 + i - 1 |
| 2987 |
if (j < size(labeltype)) then |
| 2988 |
if (grainsize(i) > 0.) then |
| 2989 |
labeltype(j) = trim(get_label_grain_size(grainsize(i)))//' dust' |
| 2990 |
else |
| 2991 |
labeltype(j) = 'dust' |
| 2992 |
endif |
| 2993 |
endif |
| 2994 |
enddo |
| 2995 |
else |
| 2996 |
labeltype(8:idustlast) = 'dust' |
| 2997 |
endif |
| 2998 |
endif |
| 2999 |
labeltype(itypemap_unknown_phantom) = 'unknown/dead' |
| 3000 |
UseTypeInRenderings(:) = .true. |
| 3001 |
UseTypeInRenderings(3) = .false. |
| 3002 |
if (lenvironment('SSPLASH_PLOT_DUST')) then |
| 3003 |
UseTypeInRenderings(2) = .false. |
| 3004 |
endif |
| 3005 |
if (lenvironment('SSPLASH_PLOT_STARS')) then |
| 3006 |
UseTypeInRenderings(5) = .false. |
| 3007 |
endif |
| 3008 |
if (lenvironment('SSPLASH_PLOT_DM')) then |
| 3009 |
UseTypeInRenderings(6) = .false. |
| 3010 |
endif |
| 3011 |
else |
| 3012 |
ntypes = 6 |
| 3013 |
labeltype(1) = 'gas' |
| 3014 |
labeltype(2) = 'dust' |
| 3015 |
labeltype(3) = 'ghost' |
| 3016 |
labeltype(4) = 'sink' |
| 3017 |
labeltype(5) = 'star' |
| 3018 |
labeltype(6) = 'unknown/dead' |
| 3019 |
UseTypeInRenderings(1) = .true. |
| 3020 |
UseTypeInRenderings(2) = .false. |
| 3021 |
UseTypeInRenderings(3) = .true. |
| 3022 |
UseTypeInRenderings(4) = .false. |
| 3023 |
UseTypeInRenderings(5) = .true. |
| 3024 |
UseTypeInRenderings(6) = .true. ! only applies if turned on |
| 3025 |
endif |
| 3026 |
|
| 3027 |
end subroutine set_labels_sphNG |
| 3028 |
|
| 3029 |
!----------------------------------------------------------- |
| 3030 |
! |
| 3031 |
! check if a file is in phantom/sphNG format |
| 3032 |
! |
| 3033 |
!----------------------------------------------------------- |
| 3034 |
logical function file_format_is_sphNG(filename) result(is_sphNG) |
| 3035 |
use byteswap, only:bs |
| 3036 |
character(len=*), intent(in) :: filename |
| 3037 |
integer :: iunit,intg1,ierr |
| 3038 |
|
| 3039 |
is_sphNG = .false. |
| 3040 |
! |
| 3041 |
! open file and read the first line |
| 3042 |
! |
| 3043 |
open(newunit=iunit,iostat=ierr,file=filename,status='old',form='unformatted') |
| 3044 |
if (ierr /= 0) return |
| 3045 |
! |
| 3046 |
! check the magic integer to determine phantom/sphNG format |
| 3047 |
! |
| 3048 |
read(iunit,iostat=ierr) intg1 |
| 3049 |
if (intg1==690706 .or. intg1==060769) is_sphNG = .true. |
| 3050 |
! |
| 3051 |
! check for sphNG but in the other endian |
| 3052 |
! |
| 3053 |
if (bs(intg1)==690706 .or. bs(intg1)==060769) is_sphNG = .true. |
| 3054 |
close(iunit) ! close the file |
| 3055 |
|
| 3056 |
end function file_format_is_sphNG |
| 3057 |
|
| 3058 |
end module readdata_sphNG |