| 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-2009 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 SKY KING / MARK MORRIS' (UCLA) ASCII DATA FORMAT |
| 28 |
! |
| 29 |
! the data is stored in the global array dat |
| 30 |
! |
| 31 |
! >> this subroutine must return values for the following: << |
| 32 |
! |
| 33 |
! ncolumns : number of data columns |
| 34 |
! ndim, ndimV : number of spatial, velocity dimensions |
| 35 |
! nstepsread : number of steps read from this file |
| 36 |
! |
| 37 |
! dat(maxplot,maxpart,maxstep) : main data array |
| 38 |
! |
| 39 |
! npartoftype(1:6,maxstep) : number of particles of each type in each timestep |
| 40 |
! ntot(maxstep) : total number of particles in each timestep |
| 41 |
! |
| 42 |
! time(maxstep) : time at each step |
| 43 |
! gamma(maxstep) : gamma at each step |
| 44 |
! |
| 45 |
! most of these values are stored in global arrays |
| 46 |
! in the module 'particle_data' |
| 47 |
!------------------------------------------------------------------------- |
| 48 |
|
| 49 |
module readdata_ucla |
| 50 |
implicit none |
| 51 |
|
| 52 |
public :: read_data_ucla, set_labels_ucla |
| 53 |
|
| 54 |
private |
| 55 |
contains |
| 56 |
|
| 57 |
subroutine read_data_UCLA(rootname,indexstart,ipos,nstepsread) |
| 58 |
use particle_data, only:dat,npartoftype,time,gamma,maxpart,maxcol,maxstep |
| 59 |
use params |
| 60 |
use settings_data, only:ndim,ndimV,ncolumns,ncalc |
| 61 |
use mem_allocation, only:alloc |
| 62 |
integer, intent(in) :: indexstart,ipos |
| 63 |
integer, intent(out) :: nstepsread |
| 64 |
character(len=*), intent(in) :: rootname |
| 65 |
integer :: i,j,ierr,nerr,iunit,ncolstep,ncolenv |
| 66 |
integer :: nprint,npart_max,nstep_max,icol |
| 67 |
integer :: igatherb,ntot,ninit,ninit1,nstar |
| 68 |
logical :: iexist |
| 69 |
real :: tread,pmass,hbav1,dttot,xmacc,xlxacc,xlyacc,xlzacc |
| 70 |
real, dimension(3) :: xptmass,yptmass,vxptmass,vyptmass |
| 71 |
character(len=len(rootname)+4) :: dumpfile |
| 72 |
|
| 73 |
nstepsread = 0 |
| 74 |
nstep_max = 0 |
| 75 |
npart_max = maxpart |
| 76 |
iunit = 15 ! logical unit number for input |
| 77 |
|
| 78 |
dumpfile = trim(rootname) |
| 79 |
! |
| 80 |
!--check if first data file exists |
| 81 |
! |
| 82 |
inquire(file=dumpfile,exist=iexist) |
| 83 |
if (.not.iexist) then |
| 84 |
print "(a)",' *** error: '//trim(dumpfile)//': file not found ***' |
| 85 |
return |
| 86 |
endif |
| 87 |
! |
| 88 |
!--fix number of spatial dimensions (0 means no particle coords) |
| 89 |
! |
| 90 |
ndim = 3 |
| 91 |
ndimV = 3 |
| 92 |
ncolstep = 10 ! create one column for particle mass |
| 93 |
nstar = 3 |
| 94 |
|
| 95 |
j = indexstart |
| 96 |
nstepsread = 0 |
| 97 |
print "(a)",' reading Sky King/Mark Morris (UCLA) ascii data format ' |
| 98 |
|
| 99 |
write(*,"(26('>'),1x,a,1x,26('<'))") trim(dumpfile) |
| 100 |
! |
| 101 |
!--open the file and read the number of particles |
| 102 |
! |
| 103 |
open(unit=iunit,iostat=ierr,file=dumpfile,status='old',form='formatted') |
| 104 |
if (ierr /= 0) then |
| 105 |
print "(a)",'*** ERROR OPENING '//trim(dumpfile)//' ***' |
| 106 |
return |
| 107 |
endif |
| 108 |
! |
| 109 |
!--read header lines, try to use it to set time |
| 110 |
! |
| 111 |
read(iunit,*,iostat=ierr) nprint,tread,pmass,xptmass(1),yptmass(1),xptmass(2),yptmass(2),& |
| 112 |
vxptmass(1),vyptmass(1),vxptmass(2),vyptmass(2), & |
| 113 |
xptmass(3),yptmass(3),vxptmass(3),vyptmass(3) |
| 114 |
if (ierr /= 0) print "(a)",' WARNING: error(s) reading first header line' |
| 115 |
print "(a,i10,a,1pe10.3)",' npart = ',nprint, ' time = ',tread |
| 116 |
|
| 117 |
read(iunit,*,iostat=ierr) igatherb,ntot,ninit,ninit1,hbav1,dttot,xmacc,xlxacc,xlyacc,xlzacc |
| 118 |
if (ierr /= 0) print "(a)",' WARNING: error(s) reading second header line' |
| 119 |
print "(a)",' header info: ' |
| 120 |
print "(2(a11,i10))",' igatherb: ',igatherb,' ntot: ',ntot |
| 121 |
print "(2(a11,i10))",' ninit: ',ninit,' ninit1: ',ninit1 |
| 122 |
print "(3(a11,1pe10.4))",' hbav1: ',hbav1,' dttot: ',dttot,' xmacc: ',xmacc |
| 123 |
print "(3(a11,1pe10.4))",' accelx: ',xlxacc,' accely: ',xlyacc,' accelz: ',xlzacc |
| 124 |
! |
| 125 |
!--(re)allocate memory |
| 126 |
! |
| 127 |
nstep_max = max(nstep_max,indexstart,1) |
| 128 |
if (.not.allocated(dat) .or. (nprint > maxpart) .or. (ncolstep+ncalc) > maxcol) then |
| 129 |
npart_max = max(npart_max,INT(1.1*(nprint)),maxpart) |
| 130 |
call alloc(npart_max,nstep_max,max(ncolstep+ncalc,maxcol)) |
| 131 |
endif |
| 132 |
! |
| 133 |
!--set the necessary parameters |
| 134 |
! |
| 135 |
ncolumns = ncolstep |
| 136 |
nstepsread = nstepsread + 1 |
| 137 |
npartoftype(:,j) = 0 |
| 138 |
npartoftype(1,j) = nprint |
| 139 |
npartoftype(2,j) = nstar |
| 140 |
time(j) = tread |
| 141 |
! |
| 142 |
!--now read the timestep data in the dumpfile |
| 143 |
! |
| 144 |
nerr = 0 |
| 145 |
do i=1,nprint |
| 146 |
read(iunit,*,iostat=ierr) (dat(i,icol,j),icol = 1,9) |
| 147 |
if (ierr /= 0) nerr = nerr + 1 |
| 148 |
enddo |
| 149 |
if (nerr > 0) print *,' ERRORS reading particle data on ',nerr,' lines' |
| 150 |
close(iunit) |
| 151 |
|
| 152 |
!--set particle mass from column |
| 153 |
dat(1:nprint,10,j) = pmass |
| 154 |
!--copy star particle properties into main data array |
| 155 |
do i=nprint+1,nprint+nstar |
| 156 |
dat(i,1,j) = xptmass(i-nprint) |
| 157 |
dat(i,2,j) = yptmass(i-nprint) |
| 158 |
dat(i,3,j) = 0. |
| 159 |
dat(i,4,j) = vxptmass(i-nprint) |
| 160 |
dat(i,5,j) = vyptmass(i-nprint) |
| 161 |
dat(i,6,j) = 0. |
| 162 |
enddo |
| 163 |
|
| 164 |
|
| 165 |
return |
| 166 |
end subroutine read_data_UCLA |
| 167 |
|
| 168 |
!!------------------------------------------------------------------- |
| 169 |
!! set labels for each column of data |
| 170 |
!! |
| 171 |
!! read these from a file called 'columns' in the current directory |
| 172 |
!! then take sensible guesses as to which quantities are which |
| 173 |
!! from the column labels |
| 174 |
!! |
| 175 |
!!------------------------------------------------------------------- |
| 176 |
|
| 177 |
subroutine set_labels_UCLA |
| 178 |
use labels, only:label,labeltype,ix,irho,ipmass,ih,ipr,ivx,iamvec,labelvec |
| 179 |
use params |
| 180 |
use settings_data, only:ncolumns,ntypes,ndim,ndimV,UseTypeInRenderings |
| 181 |
use geometry, only:labelcoord |
| 182 |
integer :: i,ierr,ndimVtemp |
| 183 |
|
| 184 |
do i=1,ndim |
| 185 |
ix(i) = i |
| 186 |
enddo |
| 187 |
ivx = 4 |
| 188 |
irho = 7 |
| 189 |
ipr = 8 |
| 190 |
ih = 9 |
| 191 |
ipmass = 10 |
| 192 |
label(irho) = 'density' |
| 193 |
label(ipr) = 'pressure' |
| 194 |
label(ih) = 'smoothing length' |
| 195 |
label(ipmass) = 'particle mass' |
| 196 |
|
| 197 |
if (ivx > 0) then |
| 198 |
iamvec(ivx:ivx+ndimV-1) = ivx |
| 199 |
labelvec(ivx:ivx+ndimV-1) = 'v' |
| 200 |
do i=1,ndimV |
| 201 |
label(ivx+i-1) = 'v\d'//labelcoord(i,1) |
| 202 |
enddo |
| 203 |
endif |
| 204 |
! |
| 205 |
!--set labels for each particle type |
| 206 |
! |
| 207 |
ntypes = 2 |
| 208 |
labeltype(1) = 'gas' |
| 209 |
labeltype(2) = 'star' |
| 210 |
UseTypeInRenderings(1) = .true. |
| 211 |
UseTypeInRenderings(2) = .false. |
| 212 |
|
| 213 |
!----------------------------------------------------------- |
| 214 |
|
| 215 |
return |
| 216 |
end subroutine set_labels_UCLA |
| 217 |
end module readdata_ucla |