| 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-2012 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 STEPHAN ROSSWOG'S CODE |
| 28 |
! (ie. STRAIGHT FROM THE DATA DUMP) |
| 29 |
! |
| 30 |
! *** CONVERTS TO SINGLE PRECISION *** |
| 31 |
! |
| 32 |
! SOME CHOICES FOR THIS FORMAT CAN BE SET USING THE FOLLOWING |
| 33 |
! ENVIRONMENT VARIABLES: |
| 34 |
! |
| 35 |
! --format or RSPLASH_FORMAT can be 'MHD' or 'HYDRO' |
| 36 |
! --com or RSPLASH_RESET_COM if 'YES' then centre of mass is reset for n2=0 (ie single objects) |
| 37 |
! --corotating or RSPLASH_COROTATING if 'YES' then velocities are transformed to corotating frame |
| 38 |
! --hfact or RSPLASH_HFACT can be changed to give correct hfact value for particle masses |
| 39 |
! on minidumps: e.g. --hfact=1.2 |
| 40 |
! |
| 41 |
! the data is stored in the global array dat |
| 42 |
! |
| 43 |
! >> this subroutine must return values for the following: << |
| 44 |
! |
| 45 |
! ncolumns : number of data columns |
| 46 |
! ndim, ndimV : number of spatial, velocity dimensions |
| 47 |
! nstepsread : number of steps read from this file |
| 48 |
! |
| 49 |
! maxplot,maxpart,maxstep : dimensions of main data array |
| 50 |
! dat(maxplot,maxpart,maxstep) : main data array |
| 51 |
! |
| 52 |
! npartoftype(1:6,maxstep) : number of particles of each type in each timestep |
| 53 |
! |
| 54 |
! time(maxstep) : time at each step |
| 55 |
! gamma(maxstep) : gamma at each step |
| 56 |
! |
| 57 |
! most of these values are stored in global arrays |
| 58 |
! in the module 'particle_data' |
| 59 |
!------------------------------------------------------------------------- |
| 60 |
|
| 61 |
module readdata_sro |
| 62 |
implicit none |
| 63 |
|
| 64 |
public :: read_data_sro, set_labels_sro |
| 65 |
|
| 66 |
private |
| 67 |
contains |
| 68 |
|
| 69 |
subroutine read_data_sro(rootname,indexstart,ipos,nstepsread) |
| 70 |
use particle_data, only:dat,time,npartoftype,gamma,maxpart,maxcol,maxstep |
| 71 |
use params |
| 72 |
use settings_data, only:ndim,ndimV,ncolumns,iformat |
| 73 |
use mem_allocation, only:alloc |
| 74 |
use system_utils, only:lenvironment,get_environment_or_flag |
| 75 |
integer, intent(in) :: indexstart,ipos |
| 76 |
integer, intent(out) :: nstepsread |
| 77 |
character(len=*), intent(in) :: rootname |
| 78 |
integer, parameter :: max_spec = 7 ! number of species in abundance file |
| 79 |
real :: hfact, dhfact3,hfacttemp |
| 80 |
integer :: i,j,k,ierr,ierr1 |
| 81 |
integer :: nprint,nptmass,npart_max,nstep_max |
| 82 |
integer :: n1,n2,idump,ncol |
| 83 |
logical :: iexist,magfield,minidump,doubleprec,iabunfileopen |
| 84 |
character(len=len(rootname)) :: dumpfile |
| 85 |
character(len=13) :: abunfile |
| 86 |
character(len=10) :: string |
| 87 |
real :: timei,tkin,tgrav,tterm,escap,rstar,mstar,Etot_burn_cgs |
| 88 |
real(doub_prec) :: timedb,tkindb,tgravdb,ttermdb |
| 89 |
real(doub_prec) :: escapdb,rstardb,mstardb,Etot_burn_cgsdb |
| 90 |
real(doub_prec), dimension(:,:), allocatable :: datdb |
| 91 |
|
| 92 |
nstepsread = 0 |
| 93 |
nstep_max = 0 |
| 94 |
npart_max = maxpart |
| 95 |
iabunfileopen = .false. |
| 96 |
hfact = 1.5 |
| 97 |
dhfact3 = 1./hfact**3 |
| 98 |
|
| 99 |
dumpfile = trim(rootname) |
| 100 |
! |
| 101 |
!--check if first data file exists |
| 102 |
! |
| 103 |
inquire(file=dumpfile,exist=iexist) |
| 104 |
if (.not.iexist) then |
| 105 |
print "(a)",' *** error: '//trim(dumpfile)//': file not found ***' |
| 106 |
return |
| 107 |
endif |
| 108 |
! |
| 109 |
!--use minidump format if minidump |
| 110 |
! |
| 111 |
minidump = .false. |
| 112 |
if (index(dumpfile,'minidump') /= 0) minidump = .true. |
| 113 |
! |
| 114 |
!--get hfact for minidumps |
| 115 |
! |
| 116 |
if (minidump) then |
| 117 |
call get_environment_or_flag('RSPLASH_HFACT',string) |
| 118 |
read(string,*,iostat=ierr) hfacttemp |
| 119 |
if (hfacttemp > 0.5 .and. hfacttemp < 10.0 .and. ierr==0) then |
| 120 |
hfact = hfacttemp |
| 121 |
print *,'setting hfact =',hfact,' from --hfact flag' |
| 122 |
else |
| 123 |
print "(1x,a)",'error reading hfact from --hfact command line flag' |
| 124 |
endif |
| 125 |
endif |
| 126 |
! |
| 127 |
!--try to guess full dump format from file names |
| 128 |
! |
| 129 |
magfield = .true. |
| 130 |
! if (.not.minidump) then |
| 131 |
! if (index(dumpfile,'SMBH') > 0) magfield = .false. |
| 132 |
! if (index(dumpfile,'nsbh') > 0) magfield = .false. |
| 133 |
! if (index(dumpfile,'NSBH') > 0) magfield = .false. |
| 134 |
! if (index(dumpfile,'WD') > 0) magfield = .false. |
| 135 |
! endif |
| 136 |
! |
| 137 |
!--override this with environment variable |
| 138 |
! |
| 139 |
call get_environment_or_flag('RSPLASH_FORMAT',string) |
| 140 |
select case(trim(adjustl(string))) |
| 141 |
case('MHD','mhd','ns','NS') |
| 142 |
magfield = .true. |
| 143 |
case('WD','hydro','HYDRO','ns_bh_v2') |
| 144 |
magfield = .false. |
| 145 |
end select |
| 146 |
|
| 147 |
if (magfield) then |
| 148 |
print "(1x,a)",'reading MAGMA code format (set --format=hydro for hydro format)' |
| 149 |
else |
| 150 |
print "(1x,a)",'reading Stephan Rosswog (hydro) code format (set --format=mhd for MAGMA)' |
| 151 |
endif |
| 152 |
|
| 153 |
! |
| 154 |
!--fix number of spatial dimensions |
| 155 |
! |
| 156 |
ndim = 3 |
| 157 |
ndimV = 3 |
| 158 |
if (magfield) then |
| 159 |
if (minidump) then |
| 160 |
ncol = 11 |
| 161 |
iformat = 1 |
| 162 |
else |
| 163 |
ncol = 27 |
| 164 |
iformat = 2 |
| 165 |
endif |
| 166 |
else |
| 167 |
if (minidump) then |
| 168 |
ncol = 7 ! number of columns in file |
| 169 |
iformat = 3 |
| 170 |
else |
| 171 |
ncol = 16 |
| 172 |
iformat = 4 |
| 173 |
endif |
| 174 |
endif |
| 175 |
n1 = 0 |
| 176 |
n2 = 0 |
| 177 |
! |
| 178 |
!--allocate memory initially |
| 179 |
! |
| 180 |
nstep_max = max(nstep_max,indexstart,1) |
| 181 |
|
| 182 |
j = indexstart |
| 183 |
nstepsread = 0 |
| 184 |
|
| 185 |
write(*,"(26('>'),1x,a,1x,26('<'))") trim(dumpfile) |
| 186 |
! |
| 187 |
!--open the (unformatted) binary file and read the number of particles |
| 188 |
! |
| 189 |
open(unit=15,iostat=ierr,file=dumpfile,status='old',form='unformatted') |
| 190 |
if (ierr /= 0) then |
| 191 |
print "(a)",'*** ERROR OPENING '//trim(dumpfile)//' ***' |
| 192 |
return |
| 193 |
else |
| 194 |
! |
| 195 |
!--read the number of particles in the first step, |
| 196 |
! allocate memory and rewind |
| 197 |
! |
| 198 |
doubleprec = .true. |
| 199 |
if (minidump) then |
| 200 |
!--try double precision first |
| 201 |
read(15,end=55,iostat=ierr) timedb,nprint,nptmass |
| 202 |
!--change to single precision if stupid answers |
| 203 |
if (nprint <= 0.or.nprint > 1e10 & |
| 204 |
.or.nptmass < 0.or.nptmass > 1e6) then |
| 205 |
doubleprec = .false. |
| 206 |
rewind(15) |
| 207 |
read(15,end=55,iostat=ierr) timei,nprint,nptmass |
| 208 |
if (magfield) then |
| 209 |
print "(a)",' single precision MHD minidump' |
| 210 |
else |
| 211 |
print "(a)",' single precision hydro minidump' |
| 212 |
endif |
| 213 |
else |
| 214 |
if (magfield) then |
| 215 |
print "(a)",' double precision MHD minidump' |
| 216 |
else |
| 217 |
print "(a)",' double precision hydro minidump' |
| 218 |
endif |
| 219 |
timei = real(timedb) |
| 220 |
endif |
| 221 |
else |
| 222 |
!--try double precision first |
| 223 |
read(15,end=55,iostat=ierr) nprint,rstardb,mstardb,n1,n2, & |
| 224 |
nptmass,timedb |
| 225 |
!--change to single precision if stupid answers |
| 226 |
if (n1 < 0.or.n1 > 1e10.or.n2 < 0.or.n2 > 1e10 & |
| 227 |
.or.nptmass < 0.or.nptmass > 1.e6) then |
| 228 |
doubleprec = .false. |
| 229 |
rewind(15) |
| 230 |
read(15,end=55,iostat=ierr) nprint,rstar,mstar,n1,n2, & |
| 231 |
nptmass,timei |
| 232 |
if (magfield) then |
| 233 |
print "(a)",' single precision full MHD dump' |
| 234 |
else |
| 235 |
print "(a)",' single precision full hydro dump' |
| 236 |
endif |
| 237 |
else |
| 238 |
if (magfield) then |
| 239 |
print "(a)",' double precision full MHD dump' |
| 240 |
else |
| 241 |
print "(a)",' double precision full hydro dump' |
| 242 |
endif |
| 243 |
timei = real(timedb) |
| 244 |
endif |
| 245 |
endif |
| 246 |
print "(a,f10.2,a,i9,a,i6)",' time: ',timei,' npart: ',nprint,' nptmass: ',nptmass |
| 247 |
!--barf if stupid answers in single and double precision |
| 248 |
if (nptmass < 0.or.nptmass > 1.e6 .or. nprint < 0 & |
| 249 |
.or. nprint > 1e10 .or. (nprint==0 .and. nptmass==0)) then |
| 250 |
print "(a)",' *** ERRORS IN TIMESTEP HEADER: NO DATA READ ***' |
| 251 |
close(15) |
| 252 |
return |
| 253 |
endif |
| 254 |
|
| 255 |
ncolumns = ncol |
| 256 |
! |
| 257 |
!--check if abundance files are present and read from them |
| 258 |
! |
| 259 |
if (.not.magfield) then |
| 260 |
!--extract dump number from filename (last 5 characters) |
| 261 |
read(dumpfile(len_trim(dumpfile)-4:len_trim(dumpfile)),*,iostat=ierr1) idump |
| 262 |
if (ierr1 /= 0) then |
| 263 |
print "(a)",' error extracting dump number from filename' |
| 264 |
else |
| 265 |
write(abunfile,"(a,'.',i5.5)") 'abun_a7',idump |
| 266 |
inquire(file=abunfile,exist=iexist) |
| 267 |
if (.not.iexist) then |
| 268 |
print "(a)",' abundance file '//trim(abunfile)//' NOT FOUND' |
| 269 |
else |
| 270 |
open(unit=41,file=abunfile,status='old',form='unformatted',iostat=ierr1) |
| 271 |
if (ierr1 /= 0) then |
| 272 |
print "(a)",'*** ERROR OPENING '//trim(abunfile) |
| 273 |
else |
| 274 |
ncolumns = ncol + max_spec + 2 |
| 275 |
iabunfileopen = .true. |
| 276 |
endif |
| 277 |
endif |
| 278 |
endif |
| 279 |
endif |
| 280 |
|
| 281 |
if (.not.allocated(dat) .or. (nprint+nptmass) > npart_max) then |
| 282 |
npart_max = max(npart_max,INT(1.1*(nprint+nptmass))) |
| 283 |
call alloc(npart_max,nstep_max,ncolumns) |
| 284 |
endif |
| 285 |
rewind(15) |
| 286 |
endif |
| 287 |
if (ierr /= 0) then |
| 288 |
print "(a)",'*** ERROR READING TIMESTEP HEADER ***' |
| 289 |
else |
| 290 |
! |
| 291 |
!--loop over the timesteps in this file |
| 292 |
! |
| 293 |
npart_max = max(npart_max,nprint) |
| 294 |
! |
| 295 |
!--allocate/reallocate memory if j > maxstep |
| 296 |
! |
| 297 |
if (j > maxstep) then |
| 298 |
call alloc(maxpart,j+1,maxcol) |
| 299 |
endif |
| 300 |
! |
| 301 |
!--now read the timestep data in the dumpfile |
| 302 |
! |
| 303 |
if (magfield) then |
| 304 |
if (minidump) then |
| 305 |
dat(:,:,j) = 0. |
| 306 |
|
| 307 |
if (doubleprec) then |
| 308 |
allocate(datdb(maxpart,ncol),stat=ierr) |
| 309 |
if (ierr /= 0) then |
| 310 |
print*,"(a)",'*** error allocating memory for double conversion ***' |
| 311 |
return |
| 312 |
else |
| 313 |
datdb = 0. |
| 314 |
endif |
| 315 |
read(15,end=55,iostat=ierr) timedb,nprint,nptmass, & |
| 316 |
((datdb(i,k),i=1,nprint),k=1,6), & |
| 317 |
((datdb(i,k),i=1,nprint),k=8,ncol), & |
| 318 |
(datdb(i,7), i=nprint+1, nprint+nptmass), & |
| 319 |
((datdb(i,k), i=nprint+1, nprint+nptmass),k=1,3) |
| 320 |
|
| 321 |
if (ierr /= 0) print "(a)",'*** WARNING: ERRORS DURING READ ***' |
| 322 |
dat(:,1:ncol,j) = real(datdb(:,1:ncol)) |
| 323 |
time(j) = real(timedb) |
| 324 |
|
| 325 |
else |
| 326 |
read(15,end=55,iostat=ierr) time(j),nprint,nptmass, & |
| 327 |
((dat(i,k,j),i=1,nprint),k=1,6), & |
| 328 |
((dat(i,k,j),i=1,nprint),k=8,ncol), & |
| 329 |
(dat(i,7,j), i=nprint+1, nprint+nptmass), & |
| 330 |
((dat(i,k,j), i=nprint+1, nprint+nptmass),k=1,3) |
| 331 |
endif |
| 332 |
! |
| 333 |
!--because masses are not dumped, we need to reconstruct them |
| 334 |
! from density and h (only strictly true for grad h code) |
| 335 |
! |
| 336 |
dat(1:nprint,7,j) = dat(1:nprint,4,j)**3*dat(1:nprint,5,j)*dhfact3 |
| 337 |
print "(a,f5.2,a)", & |
| 338 |
' WARNING: setting particle masses assuming h = ',hfact,'*(m/rho)^(1/3)' |
| 339 |
else |
| 340 |
|
| 341 |
dat(:,:,j) = 0. ! because ptmasses don't have all quantities |
| 342 |
! |
| 343 |
!--read full dump |
| 344 |
! |
| 345 |
if (doubleprec) then |
| 346 |
allocate(datdb(maxpart,27),stat=ierr) |
| 347 |
if (ierr /= 0) then |
| 348 |
print*,"(a)",'*** error allocating memory for double conversion ***' |
| 349 |
return |
| 350 |
else |
| 351 |
datdb = 0. |
| 352 |
endif |
| 353 |
read(15,iostat=ierr) nprint,rstardb,mstardb,n1,n2, & |
| 354 |
nptmass,timedb,(datdb(i,7),i=1,nprint), & |
| 355 |
escapdb,tkindb,tgravdb,ttermdb, & |
| 356 |
((datdb(i,k),i=1,nprint),k=1,6), & |
| 357 |
((datdb(i,k),i=1,nprint),k=8,ncol), & |
| 358 |
(datdb(i,9), i=nprint+1, nprint+nptmass), & |
| 359 |
((datdb(i,k), i=nprint+1, nprint+nptmass),k=1,6), & |
| 360 |
((datdb(i,k), i=nprint+1, nprint+nptmass),k=21,23) |
| 361 |
|
| 362 |
if (ierr < 0) print "(a)",'*** WARNING: END OF FILE DURING READ ***' |
| 363 |
if (ierr > 0) print "(a)",'*** WARNING: ERRORS DURING READ ***' |
| 364 |
dat(:,1:ncol,j) = real(datdb(:,1:ncol)) |
| 365 |
time(j) = real(timedb) |
| 366 |
|
| 367 |
else |
| 368 |
read(15,iostat=ierr) nprint,rstar,mstar,n1,n2, & |
| 369 |
nptmass,time(j),(dat(i,7,j),i=1,nprint), & |
| 370 |
escap,tkin,tgrav,tterm, & |
| 371 |
((dat(i,k,j),i=1,nprint),k=1,6), & |
| 372 |
((dat(i,k,j),i=1,nprint),k=8,ncol), & |
| 373 |
(dat(i,9,j), i=nprint+1, nprint+nptmass), & |
| 374 |
((dat(i,k,j), i=nprint+1, nprint+nptmass),k=1,6), & |
| 375 |
((dat(i,k,j), i=nprint+1, nprint+nptmass),k=21,23) |
| 376 |
|
| 377 |
if (ierr < 0) print "(a)",'*** WARNING: END OF FILE DURING READ ***' |
| 378 |
if (ierr > 0) print "(a)",'*** WARNING: ERRORS DURING READ ***' |
| 379 |
|
| 380 |
endif |
| 381 |
endif |
| 382 |
else |
| 383 |
! |
| 384 |
!--hydro minidumps |
| 385 |
! |
| 386 |
if (minidump) then |
| 387 |
if (doubleprec) then |
| 388 |
allocate(datdb(maxpart,7),stat=ierr) |
| 389 |
if (ierr /= 0) then |
| 390 |
print*,"(a)",'*** error allocating memory for double conversion ***' |
| 391 |
return |
| 392 |
else |
| 393 |
datdb = 0. |
| 394 |
endif |
| 395 |
read(15,end=55,iostat=ierr) timedb,nprint,nptmass, & |
| 396 |
((datdb(i,k), i=1, nprint),k=1,6), & |
| 397 |
(datdb(i,7), i=nprint+1, nprint+nptmass), & |
| 398 |
((datdb(i,k), i=nprint+1, nprint+nptmass),k=1,3) |
| 399 |
|
| 400 |
if (ierr < 0) print "(a)",'*** WARNING: END OF FILE DURING READ ***' |
| 401 |
if (ierr > 0) print "(a)",'*** WARNING: ERRORS DURING READ ***' |
| 402 |
dat(:,1:ncol,j) = real(datdb(:,1:ncol)) |
| 403 |
time(j) = real(timedb) |
| 404 |
else |
| 405 |
read(15,end=55,iostat=ierr) time(j),nprint,nptmass, & |
| 406 |
((dat(i,k,j), i=1, nprint),k=1,6), & |
| 407 |
(dat(i,7,j), i=nprint+1, nprint+nptmass), & |
| 408 |
((dat(i,k,j), i=nprint+1, nprint+nptmass),k=1,3) |
| 409 |
endif |
| 410 |
! |
| 411 |
!--because masses are not dumped, we need to reconstruct them |
| 412 |
! from density and h (only strictly true for grad h code) |
| 413 |
! |
| 414 |
dat(1:nprint,7,j) = dat(1:nprint,4,j)**3*dat(1:nprint,5,j)*dhfact3 |
| 415 |
print "(a,f5.2,a)", & |
| 416 |
' WARNING: setting particle masses assuming h = ',hfact,'*(m/rho)^(1/3)' |
| 417 |
else |
| 418 |
! |
| 419 |
!--hydro full dumps |
| 420 |
! |
| 421 |
dat(:,:,j) = 0. ! because ptmasses don't have all quantities |
| 422 |
|
| 423 |
if (doubleprec) then |
| 424 |
allocate(datdb(maxpart,ncol),stat=ierr) |
| 425 |
if (ierr /= 0) then |
| 426 |
print*,"(a)",'*** error allocating memory for double conversion ***' |
| 427 |
return |
| 428 |
else |
| 429 |
datdb = 0. |
| 430 |
endif |
| 431 |
read(15,iostat=ierr) nprint,rstardb,mstardb,n1,n2, & |
| 432 |
nptmass,timedb,(datdb(i,7),i=1,nprint), & |
| 433 |
escapdb,tkindb,tgravdb,ttermdb, & |
| 434 |
((datdb(i,k),i=1,nprint),k=1,6), & |
| 435 |
((datdb(i,k),i=1,nprint),k=8,ncol), & |
| 436 |
(datdb(i,9), i=nprint+1, nprint+nptmass), & |
| 437 |
((datdb(i,k), i=nprint+1, nprint+nptmass),k=1,6), & |
| 438 |
((datdb(i,k), i=nprint+1, nprint+nptmass),k=13,15) |
| 439 |
|
| 440 |
if (ierr < 0) print "(a)",'*** WARNING: END OF FILE DURING READ ***' |
| 441 |
if (ierr > 0) print "(a)",'*** WARNING: ERRORS DURING READ ***' |
| 442 |
dat(:,1:ncol,j) = real(datdb(:,1:ncol)) |
| 443 |
time(j) = real(timedb) |
| 444 |
|
| 445 |
else |
| 446 |
read(15,iostat=ierr) nprint,rstar,mstar,n1,n2, & |
| 447 |
nptmass,time(j),(dat(i,7,j),i=1,nprint), & |
| 448 |
escap,tkin,tgrav,tterm, & |
| 449 |
((dat(i,k,j),i=1,nprint),k=1,6), & |
| 450 |
((dat(i,k,j),i=1,nprint),k=8,ncol), & |
| 451 |
(dat(i,9,j), i=nprint+1, nprint+nptmass), & |
| 452 |
((dat(i,k,j), i=nprint+1, nprint+nptmass),k=1,6), & |
| 453 |
((dat(i,k,j), i=nprint+1, nprint+nptmass),k=13,15) |
| 454 |
|
| 455 |
if (ierr < 0) print "(a)",'*** WARNING: END OF FILE DURING READ ***' |
| 456 |
if (ierr > 0) print "(a)",'*** WARNING: ERRORS DURING READ ***' |
| 457 |
|
| 458 |
endif |
| 459 |
endif |
| 460 |
endif |
| 461 |
|
| 462 |
if (ierr /= 0 ) then |
| 463 |
print "(a)",'|*** ERROR READING TIMESTEP ***' |
| 464 |
! return |
| 465 |
! else |
| 466 |
! nstepsread = nstepsread + 1 |
| 467 |
endif |
| 468 |
nstepsread = nstepsread + 1 |
| 469 |
|
| 470 |
npartoftype(1,j) = nprint |
| 471 |
npartoftype(2,j) = nptmass |
| 472 |
!! print*,j,' time = ',time(j) |
| 473 |
gamma(j) = 1.666666666667 |
| 474 |
! |
| 475 |
!--read abundances from abundance file |
| 476 |
! |
| 477 |
if (iabunfileopen) then |
| 478 |
print "(a)",' ... reading abundances from '//trim(abunfile)//' ...' |
| 479 |
read(41,iostat=ierr1) nprint |
| 480 |
if (ierr1 /= 0) then |
| 481 |
print "(a)",' *** ERROR READING ABUNDANCE FILE ***' |
| 482 |
elseif (nprint /= npartoftype(1,j)) then |
| 483 |
print "(a)",' *** ERROR: npart in abundance file differs from full dump ***' |
| 484 |
else |
| 485 |
rewind(41) |
| 486 |
if (doubleprec) then |
| 487 |
read(41,iostat=ierr1) nprint,((datdb(i,k),k=1,max_spec+2),i=1,nprint),Etot_burn_cgsdb |
| 488 |
dat(:,ncol+1:ncolumns,j) = real(datdb(:,1:max_spec+2)) |
| 489 |
print*,' Etot_burn (cgs) = ',Etot_burn_cgsdb |
| 490 |
else |
| 491 |
read(41,iostat=ierr1) nprint,((dat(i,k,j),k=1,max_spec+2),i=1,nprint),Etot_burn_cgs |
| 492 |
print*,' Etot_burn (cgs) = ',Etot_burn_cgs |
| 493 |
endif |
| 494 |
if (ierr1 < 0) then |
| 495 |
print "(a)",' *** END OF FILE REACHED IN ABUNDANCE FILE ***' |
| 496 |
elseif (ierr1 > 0) then |
| 497 |
print "(a)",' *** ERRORS DURING ABUNDANCE FILE READ ***' |
| 498 |
elseif (nprint /= npartoftype(1,j)) then |
| 499 |
print "(a)",' *** ERROR: npart in abundance file differs from full dump ***' |
| 500 |
endif |
| 501 |
endif |
| 502 |
close(unit=41) |
| 503 |
endif |
| 504 |
|
| 505 |
j = j + 1 |
| 506 |
|
| 507 |
if (allocated(datdb)) deallocate(datdb) |
| 508 |
|
| 509 |
endif |
| 510 |
|
| 511 |
55 continue |
| 512 |
! |
| 513 |
!--reached end of file |
| 514 |
! |
| 515 |
close(15) |
| 516 |
|
| 517 |
! |
| 518 |
!--reset centre of mass to zero |
| 519 |
! |
| 520 |
if (allocated(dat) .and. n2==0 .and. lenvironment('RSPLASH_RESET_CM')) then |
| 521 |
if (minidump) then |
| 522 |
call reset_centre_of_mass(dat(1:nprint,1:3,j-1),dat(1:nprint,7,j-1),nprint) |
| 523 |
else ! full dumps ipmass = 9 |
| 524 |
call reset_centre_of_mass(dat(1:nprint,1:3,j-1),dat(1:nprint,9,j-1),nprint) |
| 525 |
endif |
| 526 |
endif |
| 527 |
|
| 528 |
! |
| 529 |
!--transform velocities to corotating frame |
| 530 |
! |
| 531 |
if (.not.minidump .and. allocated(dat) .and. lenvironment('RSPLASH_COROTATING')) then |
| 532 |
print*,'TRANSFORMING VELOCITIES TO CORORATING FRAME' |
| 533 |
call set_corotating_vels(dat(1:nprint,9,j-1),dat(1:nprint,4:5,j-1),n1,nprint) |
| 534 |
endif |
| 535 |
|
| 536 |
if (allocated(npartoftype)) then |
| 537 |
print*,'>> end of dump file: nsteps =',j-1,'ntot = ', & |
| 538 |
sum(npartoftype(:,j-1)),'nptmass=',npartoftype(2,j-1) |
| 539 |
endif |
| 540 |
return |
| 541 |
|
| 542 |
contains |
| 543 |
|
| 544 |
! |
| 545 |
!--reset centre of mass to zero |
| 546 |
! |
| 547 |
subroutine reset_centre_of_mass(xyz,pmass,npart) |
| 548 |
integer, intent(in) :: npart |
| 549 |
real, dimension(npart,3), intent(inout) :: xyz |
| 550 |
real, dimension(npart) :: pmass |
| 551 |
real :: masstot,xcm,ycm,zcm |
| 552 |
|
| 553 |
! |
| 554 |
!--get centre of mass |
| 555 |
! |
| 556 |
masstot = SUM(pmass(1:npart)) |
| 557 |
xcm = SUM(pmass(1:npart)*xyz(1:npart,1))/masstot |
| 558 |
ycm = SUM(pmass(1:npart)*xyz(1:npart,2))/masstot |
| 559 |
zcm = SUM(pmass(1:npart)*xyz(1:npart,3))/masstot |
| 560 |
|
| 561 |
print*,' centre of mass is at ',xcm,ycm,zcm |
| 562 |
print*,' resetting to zero...' |
| 563 |
xyz(1:npart,1) = xyz(1:npart,1) - xcm |
| 564 |
xyz(1:npart,2) = xyz(1:npart,2) - ycm |
| 565 |
xyz(1:npart,3) = xyz(1:npart,3) - zcm |
| 566 |
|
| 567 |
return |
| 568 |
end subroutine reset_centre_of_mass |
| 569 |
|
| 570 |
! |
| 571 |
!--adjust velocities to corotating frame |
| 572 |
! |
| 573 |
subroutine set_corotating_vels(pmass,vxy,n1,npart) |
| 574 |
integer, intent(in) :: n1,npart |
| 575 |
real, dimension(npart,2), intent(inout) :: vxy !, xy |
| 576 |
real, dimension(npart) :: pmass |
| 577 |
real :: mass1,mass2 !,xcm1,ycm1,xcm2,ycm2 |
| 578 |
real :: vxcm1,vycm1,vxcm2,vycm2 |
| 579 |
|
| 580 |
! |
| 581 |
!--get centre of mass of star 1 and star 2 |
| 582 |
! |
| 583 |
mass1 = SUM(pmass(1:n1)) |
| 584 |
! xcm1 = SUM(pmass(1:n1)*xy(1:n1,1))/mass1 |
| 585 |
! ycm1 = SUM(pmass(1:n1)*xy(1:n1,2))/mass1 |
| 586 |
|
| 587 |
mass2 = SUM(pmass(n1+1:npart)) |
| 588 |
! xcm2 = SUM(pmass(n1+1:npart)*xy(n1+1:npart,1))/mass2 |
| 589 |
! ycm2 = SUM(pmass(n1+1:npart)*xy(n1+1:npart,2))/mass2 |
| 590 |
! |
| 591 |
!--work out centre of mass velocities for each star |
| 592 |
! |
| 593 |
vxcm1 = SUM(pmass(1:n1)*vxy(1:n1,1))/mass1 |
| 594 |
vycm1 = SUM(pmass(1:n1)*vxy(1:n1,2))/mass1 |
| 595 |
|
| 596 |
vxcm2 = SUM(pmass(n1+1:npart)*vxy(n1+1:npart,1))/mass2 |
| 597 |
vycm2 = SUM(pmass(n1+1:npart)*vxy(n1+1:npart,2))/mass2 |
| 598 |
|
| 599 |
! |
| 600 |
!--subtract centre of mass velocities appropriately |
| 601 |
! |
| 602 |
vxy(1:n1,1) = vxy(1:n1,1) - vxcm1 |
| 603 |
vxy(1:n1,2) = vxy(1:n1,2) - vycm1 |
| 604 |
vxy(n1+1:npart,1) = vxy(n1+1:npart,1) - vxcm2 |
| 605 |
vxy(n1+1:npart,2) = vxy(n1+1:npart,2) - vycm2 |
| 606 |
|
| 607 |
end subroutine set_corotating_vels |
| 608 |
|
| 609 |
end subroutine read_data_sro |
| 610 |
|
| 611 |
!!------------------------------------------------------------ |
| 612 |
!! set labels for each column of data |
| 613 |
!!------------------------------------------------------------ |
| 614 |
|
| 615 |
subroutine set_labels_sro |
| 616 |
use filenames, only:rootname |
| 617 |
use labels, only:label,unitslabel=>unitslabel_default,labelvec,labeltype,iamvec,& |
| 618 |
ix,ivx,ih,irho,iutherm,ipmass,iBfirst,idivB,make_vector_label |
| 619 |
use settings_data, only:ndim,ndimV,ncolumns,ntypes,UseTypeInRenderings,iformat |
| 620 |
use geometry, only:labelcoord |
| 621 |
use settings_units, only:units=>units_default |
| 622 |
integer :: i |
| 623 |
logical :: minidump |
| 624 |
real :: udistcm,udistkm,utime,umass,uvelkms |
| 625 |
|
| 626 |
minidump = .false. |
| 627 |
if (index(rootname(1),'minidump') /= 0) minidump = .true. |
| 628 |
|
| 629 |
if (ndim <= 0 .or. ndim > 3) then |
| 630 |
print*,'*** ERROR: ndim = ',ndim,' in set_labels_sro ***' |
| 631 |
return |
| 632 |
endif |
| 633 |
if (ndimV <= 0 .or. ndimV > 3) then |
| 634 |
print*,'*** ERROR: ndimV = ',ndimV,' in set_labels_sro ***' |
| 635 |
return |
| 636 |
endif |
| 637 |
|
| 638 |
do i=1,ndim |
| 639 |
ix(i) = i |
| 640 |
enddo |
| 641 |
if (minidump) then |
| 642 |
ivx = 0 |
| 643 |
ih = 4 ! smoothing length |
| 644 |
irho = 5 ! location of rho in data array |
| 645 |
iutherm = 0 ! thermal energy |
| 646 |
ipmass = 7 ! particle mass |
| 647 |
label(6) = 'T' |
| 648 |
if (ncolumns > 7) then |
| 649 |
iBfirst = 8 |
| 650 |
idivB = 11 |
| 651 |
endif |
| 652 |
if (ncolumns > 11) then |
| 653 |
label(12) = 'grad h' |
| 654 |
label(13) = 'grad soft' |
| 655 |
label(14) = 'dsoft' |
| 656 |
endif |
| 657 |
! |
| 658 |
!--set transformation factors between code units/real units |
| 659 |
! |
| 660 |
udistkm = 1.5 ! km |
| 661 |
udistcm = 1.5e5 |
| 662 |
utime = 5.0415e-6 |
| 663 |
umass = 1.99e33 |
| 664 |
units(1:3) = udistkm |
| 665 |
unitslabel(1:3) = ' [km]' |
| 666 |
units(ih) = udistkm |
| 667 |
unitslabel(ih) = ' [km]' |
| 668 |
units(ipmass) = umass |
| 669 |
unitslabel(ipmass) = ' [g]' |
| 670 |
units(irho) = umass/udistcm**3 |
| 671 |
unitslabel(irho) = ' [g/cm^3]' |
| 672 |
if (iBfirst > 0) then |
| 673 |
units(iBfirst:iBfirst+ndimV-1) = 8.0988e14 |
| 674 |
unitslabel(iBfirst:iBfirst+ndimV-1) = ' [G]' |
| 675 |
units(idivB) = units(iBfirst)/udistcm |
| 676 |
unitslabel(idivB) = ' [G/cm]' |
| 677 |
endif |
| 678 |
|
| 679 |
else !--full dump |
| 680 |
ivx = ndim+1 |
| 681 |
ih = 7 |
| 682 |
iutherm = 8 |
| 683 |
ipmass = 9 |
| 684 |
irho = 10 |
| 685 |
label(11) = 'temperature [ MeV ]' |
| 686 |
label(12) = 'electron fraction (y_{e})' |
| 687 |
|
| 688 |
if (iformat==2) then ! MHD full dump |
| 689 |
iBfirst = 13 |
| 690 |
label(16) = 'psi' |
| 691 |
idivB = 17 |
| 692 |
call make_vector_label('force',18,ndimV,iamvec,labelvec,label,labelcoord(:,1)) |
| 693 |
|
| 694 |
label(21) = 'Euler alpha' |
| 695 |
label(22) = 'Euler beta' |
| 696 |
label(23) = 'Bevol\dz' |
| 697 |
label(24) = 'grad h' |
| 698 |
label(25) = 'grad soft' |
| 699 |
label(26) = 'av ' |
| 700 |
label(27) = 'avB' |
| 701 |
! |
| 702 |
!--set transformation factors between code units/real units |
| 703 |
! |
| 704 |
udistkm = 1.5 ! km |
| 705 |
udistcm = 1.5e5 |
| 706 |
utime = 5.0415e-6 |
| 707 |
umass = 1.99e33 |
| 708 |
|
| 709 |
units(iBfirst:iBfirst+ndimV-1) = 8.0988e14 |
| 710 |
unitslabel(iBfirst:iBfirst+ndimV-1) = ' [G]' |
| 711 |
units(idivB) = units(iBfirst)/udistcm |
| 712 |
unitslabel(idivB) = ' [G/cm]' |
| 713 |
|
| 714 |
units(1:3) = udistkm |
| 715 |
unitslabel(1:3) = ' [km]' |
| 716 |
units(4:6) = 1.0 |
| 717 |
unitslabel(4:6) = '/c' |
| 718 |
units(7) = udistkm |
| 719 |
unitslabel(7) = ' [km]' |
| 720 |
units(8) = (udistcm/utime)**2 |
| 721 |
unitslabel(8) = ' [erg/g]' |
| 722 |
units(9) = umass |
| 723 |
unitslabel(9) = ' [g]' |
| 724 |
units(10) = umass/udistcm**3 |
| 725 |
unitslabel(10) = ' [g/cm^3]' |
| 726 |
|
| 727 |
else |
| 728 |
call make_vector_label('force',13,ndimV,iamvec,labelvec,label,labelcoord(:,1)) |
| 729 |
label(16) = 'dgrav' |
| 730 |
if (ncolumns > 16) then |
| 731 |
label(11) = 'temperature [ 10^6 K ]' |
| 732 |
do i=17,ncolumns |
| 733 |
write(label(i),"('species ',i2)") i-16 |
| 734 |
enddo |
| 735 |
if (ncolumns >= 25) then |
| 736 |
label(17) = 'He' |
| 737 |
label(18) = 'C' |
| 738 |
label(19) = 'O' |
| 739 |
label(20) = 'Ne' |
| 740 |
label(21) = 'Mg' |
| 741 |
label(22) = 'Si' |
| 742 |
label(23) = 'Fe' |
| 743 |
label(24) = 'mean A' |
| 744 |
label(25) = 'mean Z' |
| 745 |
endif |
| 746 |
endif |
| 747 |
|
| 748 |
udistcm = 1.0e9 |
| 749 |
utime = 2.7443 |
| 750 |
umass = 1.99e33 |
| 751 |
uvelkms = (udistcm/utime)/1e5 |
| 752 |
|
| 753 |
units(1:3) = 1.0 !!udistcm |
| 754 |
unitslabel(1:3) = ' [10^9 cm]' |
| 755 |
units(4:6) = uvelkms |
| 756 |
unitslabel(4:6) = ' [km/s]' |
| 757 |
units(ih) = units(1) |
| 758 |
unitslabel(ih) = unitslabel(1) |
| 759 |
units(8) = (udistcm/utime)**2 |
| 760 |
unitslabel(8) = ' [erg/g]' |
| 761 |
units(9) = umass |
| 762 |
unitslabel(9) = ' [g]' |
| 763 |
units(10) = umass/udistcm**3 |
| 764 |
unitslabel(10) = ' [g/cm^3]' |
| 765 |
endif |
| 766 |
|
| 767 |
endif |
| 768 |
|
| 769 |
units(0) = utime*1000. |
| 770 |
unitslabel(0) = ' ms' |
| 771 |
|
| 772 |
call make_vector_label('v',ivx,ndimV,iamvec,labelvec,label,labelcoord(:,1)) |
| 773 |
call make_vector_label('B',iBfirst,ndimV,iamvec,labelvec,label,labelcoord(:,1)) |
| 774 |
if (iBfirst /= 0) label(idivB) = 'div B' |
| 775 |
|
| 776 |
label(ix(1:ndim)) = labelcoord(1:ndim,1) |
| 777 |
label(irho) = '\gr' |
| 778 |
if (iutherm > 0) label(iutherm) = 'u' |
| 779 |
label(ih) = 'h ' |
| 780 |
label(ipmass) = 'particle mass' |
| 781 |
! |
| 782 |
!--set labels for each particle type |
| 783 |
! |
| 784 |
ntypes = 2 !!maxparttypes |
| 785 |
labeltype(1) = 'gas' |
| 786 |
labeltype(2) = 'point mass' |
| 787 |
UseTypeInRenderings(1) = .true. |
| 788 |
UseTypeInRenderings(2) = .false. |
| 789 |
|
| 790 |
end subroutine set_labels_sro |
| 791 |
end module readdata_sro |