| 1 |
!----------------------------------------------------------------- |
| 2 |
! |
| 3 |
! This file is (or was) part of SPLASH, a visualisation tool |
| 4 |
! for Smoothed Particle Hydrodynamics written by Daniel Price: |
| 5 |
! |
| 6 |
! http://users.monash.edu.au/~dprice/splash |
| 7 |
! |
| 8 |
! SPLASH comes with ABSOLUTELY NO WARRANTY. |
| 9 |
! This is free software; and you are welcome to redistribute |
| 10 |
! it under the terms of the GNU General Public License |
| 11 |
! (see LICENSE file for details) and the provision that |
| 12 |
! this notice remains intact. If you modify this file, please |
| 13 |
! note section 2a) of the GPLv2 states that: |
| 14 |
! |
| 15 |
! a) You must cause the modified files to carry prominent notices |
| 16 |
! stating that you changed the files and the date of any change. |
| 17 |
! |
| 18 |
! Copyright (C) 2005-2016 Daniel Price. All rights reserved. |
| 19 |
! Contact: [email protected] |
| 20 |
! |
| 21 |
!----------------------------------------------------------------- |
| 22 |
|
| 23 |
!------------------------------------------------------------------------- |
| 24 |
! this subroutine reads from the data file(s) |
| 25 |
! change this to change the format of data input |
| 26 |
! |
| 27 |
! the data is stored in the global array dat |
| 28 |
! |
| 29 |
! THIS VERSION FOR RSPH BINARY DUMPS |
| 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 |
! maxplot,maxpart,maxstep : dimensions of main data array |
| 38 |
! dat(maxplot,maxpart,maxstep) : main data array |
| 39 |
! |
| 40 |
! npartoftype(maxstep) : number of particles of each type 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_rsph |
| 50 |
implicit none |
| 51 |
|
| 52 |
public :: read_data_rsph, set_labels_rsph |
| 53 |
|
| 54 |
private |
| 55 |
contains |
| 56 |
|
| 57 |
|
| 58 |
subroutine read_data_rsph(rootname,indexstart,ipos,nstepsread) |
| 59 |
use particle_data, only:npartoftype,time,gamma,dat,maxpart,maxstep,maxcol |
| 60 |
use params |
| 61 |
! use labels |
| 62 |
use filenames, only:nfiles |
| 63 |
use settings_data, only:ndim,ndimV,ncolumns,ncalc,ntypes, & |
| 64 |
buffer_data |
| 65 |
use mem_allocation, only:alloc |
| 66 |
use geometry, only:labelcoordsys |
| 67 |
integer, intent(in) :: indexstart,ipos |
| 68 |
integer, intent(out) :: nstepsread |
| 69 |
character(len=*), intent(in) :: rootname |
| 70 |
character(len=len(rootname)+4) :: datfile |
| 71 |
integer :: i,icol,ierr,iunit,isizeheader |
| 72 |
integer :: npart_max,nstep_max |
| 73 |
integer :: ntoti |
| 74 |
logical :: singleprecision |
| 75 |
|
| 76 |
integer*2, dimension(10) :: sheader |
| 77 |
integer, dimension(10) :: iheader |
| 78 |
integer*8, dimension(10):: lheader |
| 79 |
real, dimension(10) :: rheader |
| 80 |
real(doub_prec), dimension(10) :: dheader |
| 81 |
character(len=100) :: headerstring |
| 82 |
character(len=10), dimension(maxplot) :: cheader |
| 83 |
real, dimension(:,:), allocatable :: dattemp |
| 84 |
real(doub_prec), dimension(:,:), allocatable :: dattempd |
| 85 |
common /chead/ cheader |
| 86 |
|
| 87 |
iunit = 11 ! file unit number |
| 88 |
nstepsread = 0 |
| 89 |
if (rootname(1:1) /= ' ') then |
| 90 |
datfile = trim(rootname) |
| 91 |
!print*,'rootname = ',rootname |
| 92 |
else |
| 93 |
print*,' **** no data read **** ' |
| 94 |
return |
| 95 |
endif |
| 96 |
|
| 97 |
print "(1x,a)",'reading RSPH format' |
| 98 |
write(*,"(23('-'),1x,a,1x,23('-'))") trim(datfile) |
| 99 |
! |
| 100 |
!--open data file and read data |
| 101 |
! |
| 102 |
open(unit=iunit,iostat=ierr,file=datfile,status='old',form='unformatted') |
| 103 |
if (ierr /= 0) then |
| 104 |
print*,'*** Error opening '//trim(datfile)//' ***' |
| 105 |
return |
| 106 |
endif |
| 107 |
|
| 108 |
i = indexstart |
| 109 |
! |
| 110 |
!--read first header line |
| 111 |
! |
| 112 |
read(iunit,iostat=ierr,end=80) headerstring |
| 113 |
print "(1x,a)",'header string="'//trim(headerstring)//'"' |
| 114 |
! |
| 115 |
!--read other header lines (short/normal/long ints, reals, doubles) |
| 116 |
! |
| 117 |
read(iunit,iostat=ierr,end=80) sheader(1:10) |
| 118 |
if (ierr /= 0) then |
| 119 |
print*,'WARNING: errors during sheader read' |
| 120 |
endif |
| 121 |
print "(1x,a,10(1x,i2))",'sheader = ',sheader(1:10) |
| 122 |
|
| 123 |
isizeheader = sheader(1) |
| 124 |
ndim = sheader(2) |
| 125 |
ndimV = sheader(3) |
| 126 |
ntypes = sheader(4) |
| 127 |
ncolumns = sheader(5) + ndim ! ncolumns in sheader + positions |
| 128 |
! |
| 129 |
!--check for errors in sheader |
| 130 |
! |
| 131 |
if (ndim > 3 .or. ndimV > 3 .or. ndim <= 0 .or. ndimV <= 0 .or. & |
| 132 |
ncolumns <= 0 ) then |
| 133 |
print*,'*** ERROR: header corrupted: ndim = ',ndim,' ndimV = ', ndimV |
| 134 |
ndim = 0 |
| 135 |
ndimV = 0 |
| 136 |
ntypes = 0 |
| 137 |
ncolumns = 0 |
| 138 |
close(iunit) |
| 139 |
return |
| 140 |
elseif (ncolumns > maxplot) then |
| 141 |
print "(1x,a)",'*** WARNING: too many columns for array limits' |
| 142 |
ncolumns = maxplot |
| 143 |
print "(1x,a,i2,a)",' reading only first ',ncolumns,' columns' |
| 144 |
endif |
| 145 |
|
| 146 |
read(iunit,iostat=ierr,end=80) iheader(1:isizeheader) |
| 147 |
if (ierr /= 0) then |
| 148 |
print*,'WARNING: errors during iheader read' |
| 149 |
endif |
| 150 |
print "(1x,a,20(1x,i6))",'iheader = ',iheader(1:isizeheader) |
| 151 |
|
| 152 |
ntoti = sum(iheader(1:ntypes)) |
| 153 |
|
| 154 |
read(iunit,iostat=ierr,end=80) lheader(1:isizeheader) |
| 155 |
if (ierr /= 0) then |
| 156 |
print*,'WARNING: errors during lheader read' |
| 157 |
endif |
| 158 |
print "(1x,a,20(1x,i6))",'lheader = ',lheader(1:isizeheader) |
| 159 |
|
| 160 |
read(iunit,iostat=ierr,end=80) rheader(1:isizeheader) |
| 161 |
if (ierr /= 0) then |
| 162 |
print*,'WARNING: errors during rheader read' |
| 163 |
endif |
| 164 |
print "(1x,a,20(1x,f8.2))",'rheader = ',rheader |
| 165 |
read(iunit,iostat=ierr,end=80) dheader(1:isizeheader) |
| 166 |
if (ierr /= 0) then |
| 167 |
print*,'WARNING: errors during dheader read' |
| 168 |
endif |
| 169 |
print "(1x,a,20(1x,1pe8.2))",'dheader = ',dheader(1:isizeheader) |
| 170 |
do icol=1,ncolumns-ndim |
| 171 |
read(iunit,iostat=ierr,end=80) cheader(icol)(1:isizeheader) |
| 172 |
enddo |
| 173 |
! print "(a)",(trim(cheader(icol)),icol=1,ncolumns-ndim) |
| 174 |
! |
| 175 |
!--allocate/reallocate memory for data arrays |
| 176 |
! |
| 177 |
if (buffer_data) then |
| 178 |
nstep_max = max(nfiles,maxstep,indexstart) |
| 179 |
else |
| 180 |
nstep_max = max(1,maxstep,indexstart) |
| 181 |
endif |
| 182 |
npart_max = max(int(2.0*ntoti),maxpart) |
| 183 |
if (.not.allocated(dat) .or. ntoti > maxpart & |
| 184 |
.or. nstep_max > maxstep .or. ncolumns > maxcol) then |
| 185 |
call alloc(npart_max,nstep_max,ncolumns+ncalc) |
| 186 |
endif |
| 187 |
! |
| 188 |
!--count this as a successful read |
| 189 |
! |
| 190 |
nstepsread = nstepsread + 1 |
| 191 |
! |
| 192 |
!--copy header data into now-allocated arrays |
| 193 |
! |
| 194 |
npartoftype(1,i) = iheader(1) |
| 195 |
npartoftype(2,i) = iheader(2) |
| 196 |
npartoftype(3,i) = iheader(3) |
| 197 |
ntoti = sum(npartoftype(1:ntypes,i)) |
| 198 |
! |
| 199 |
!--determine whether dump is single or double precision |
| 200 |
! |
| 201 |
singleprecision = .true. |
| 202 |
if (all(abs(rheader(1:isizeheader)) < tiny(rheader))) then |
| 203 |
singleprecision = .false. |
| 204 |
print "(1x,a)",'double precision dump' |
| 205 |
time(i) = real(dheader(1)) |
| 206 |
print*,'particles per smoothing length = ',dheader(2) |
| 207 |
print*,'kernel range = ',dheader(3) |
| 208 |
gamma(i) = real(dheader(4)) |
| 209 |
else |
| 210 |
print "(1x,a)",'single precision dump' |
| 211 |
time(i) = rheader(1) |
| 212 |
print*,'particles per smoothing length = ',rheader(2) |
| 213 |
print*,'kernel range = ',rheader(3) |
| 214 |
gamma(i) = rheader(4) |
| 215 |
endif |
| 216 |
|
| 217 |
print "(/a14,':',f8.4,a8,':',i8,a8,':',i8)",' time',time(i),'npart',npartoftype(1,i),'ntotal',ntoti |
| 218 |
print "(a14,':',i8,a8,':',f8.4)",' ncolumns',ncolumns,'gamma',gamma(i) |
| 219 |
print "(a14,':',i8,a8,':',i8)",'ndim',ndim,'ndimV',ndimV |
| 220 |
! |
| 221 |
!--read data arrays |
| 222 |
! |
| 223 |
if (singleprecision) then |
| 224 |
if (allocated(dattemp)) deallocate(dattemp) |
| 225 |
allocate(dattemp(ndim,ntoti)) |
| 226 |
! |
| 227 |
!--read positions of all particles |
| 228 |
! |
| 229 |
read(iunit,iostat=ierr) dattemp(1:ndim,1:ntoti) |
| 230 |
if (ierr /=0 ) then |
| 231 |
print "(a)",'error reading particle positions' |
| 232 |
else |
| 233 |
do icol=1,ndim |
| 234 |
dat(1:ntoti,icol,i) = dattemp(icol,1:ntoti) |
| 235 |
enddo |
| 236 |
endif |
| 237 |
! |
| 238 |
!--read rest of data columns |
| 239 |
! |
| 240 |
do icol=ndim+1,ncolumns |
| 241 |
read(iunit,iostat=ierr) dat(1:ntoti,icol,i) |
| 242 |
if (ierr /= 0) print "(a,i2)", 'error reading column ',icol |
| 243 |
enddo |
| 244 |
else |
| 245 |
if (allocated(dattempd)) deallocate(dattempd) |
| 246 |
allocate(dattempd(ndim,ntoti)) |
| 247 |
! |
| 248 |
!--read positions of all particles |
| 249 |
! |
| 250 |
read(iunit,iostat=ierr) dattempd(1:ndim,1:ntoti) |
| 251 |
if (ierr /=0 ) then |
| 252 |
print "(a)",'error reading particle positions' |
| 253 |
else |
| 254 |
do icol=1,ndim |
| 255 |
dat(1:ntoti,icol,i) = real(dattempd(icol,1:ntoti)) |
| 256 |
enddo |
| 257 |
endif |
| 258 |
! |
| 259 |
!--read rest of data columns |
| 260 |
! |
| 261 |
do icol=ndim+1,ncolumns |
| 262 |
read(iunit,iostat=ierr) dattempd(1,1:ntoti) |
| 263 |
if (ierr /= 0) print "(a,i2)", 'error reading column ',icol |
| 264 |
!--convert to single precision |
| 265 |
dat(1:ntoti,icol,i) = real(dattempd(1,1:ntoti)) |
| 266 |
enddo |
| 267 |
|
| 268 |
endif |
| 269 |
|
| 270 |
if (allocated(dattemp)) deallocate(dattemp) |
| 271 |
if (allocated(dattempd)) deallocate(dattempd) |
| 272 |
! |
| 273 |
!--close data file and return |
| 274 |
! |
| 275 |
close(unit=iunit) |
| 276 |
|
| 277 |
print "(a)",' finished data read ' |
| 278 |
|
| 279 |
return |
| 280 |
|
| 281 |
80 continue |
| 282 |
print*,' *** data file empty : no timesteps ***' |
| 283 |
return |
| 284 |
|
| 285 |
end subroutine read_data_rsph |
| 286 |
|
| 287 |
!!------------------------------------------------------------ |
| 288 |
!! set labels for each column of data |
| 289 |
!!------------------------------------------------------------ |
| 290 |
|
| 291 |
subroutine set_labels_rsph |
| 292 |
use labels, only:ix,ivx,ih,irho,iutherm,ipmass,ipr,iBfirst, & |
| 293 |
iamvec,labelvec,label,labeltype |
| 294 |
use params |
| 295 |
use settings_data, only:ndim,ndimV,ncolumns,ntypes, & |
| 296 |
UseTypeInRenderings |
| 297 |
use geometry, only:labelcoord |
| 298 |
integer :: i,j |
| 299 |
character(len=10), dimension(maxplot) :: cheader |
| 300 |
common /chead/ cheader |
| 301 |
|
| 302 |
if (ndim <= 0 .or. ndim > 3) then |
| 303 |
print*,'*** ERROR: ndim = ',ndim,' in set_labels_rsph ***' |
| 304 |
return |
| 305 |
endif |
| 306 |
if (ndimV <= 0 .or. ndimV > 3) then |
| 307 |
print*,'*** ERROR: ndimV = ',ndimV,' in set_labels_rsph ***' |
| 308 |
return |
| 309 |
endif |
| 310 |
|
| 311 |
do i=1,ndim |
| 312 |
ix(i) = i |
| 313 |
enddo |
| 314 |
|
| 315 |
do i=ndim+1,ncolumns |
| 316 |
label(i) = cheader(i-ndim) |
| 317 |
!--blank characters in c are ascii zero - correct these to spaces |
| 318 |
do j=1,len(label(i)) |
| 319 |
if (iachar(label(i)(j:j))==0) label(i)(j:j) = ' ' |
| 320 |
enddo |
| 321 |
!--set positions of various quantities depending on labels |
| 322 |
if (label(i)(1:1)=='m' .or. label(i)(1:4)=='mass') then |
| 323 |
ipmass = i |
| 324 |
elseif (label(i)(1:3)=='rho' .or. label(i)(1:4)=='dens') then |
| 325 |
irho = i |
| 326 |
elseif (label(i)(1:1)=='h' .or. label(i)(1:6)=='smooth') then |
| 327 |
ih = i |
| 328 |
elseif (label(i)(1:2)=='u ' .or. label(i)(1:1)=='e') then |
| 329 |
iutherm = i |
| 330 |
elseif (label(i)(1:2)=='pr' .or. trim(label(i))=='P') then |
| 331 |
ipr = i |
| 332 |
elseif (label(i)(1:1)=='v') then |
| 333 |
if (ivx==0 .or. i < ivx) ivx = i |
| 334 |
elseif (label(i)(1:1)=='B') then |
| 335 |
if (iBfirst==0 .or. i < iBfirst) iBfirst = i |
| 336 |
endif |
| 337 |
enddo |
| 338 |
|
| 339 |
label(ix(1:ndim)) = labelcoord(1:ndim,1) |
| 340 |
! |
| 341 |
!--label vector quantities (e.g. velocity) appropriately |
| 342 |
! |
| 343 |
if (ivx > 0) then |
| 344 |
iamvec(ivx:ivx+ndimV-1) = ivx |
| 345 |
labelvec(ivx:ivx+ndimV-1) = 'v' |
| 346 |
do i=1,ndimV |
| 347 |
label(ivx+i-1) = trim(labelvec(ivx+i-1))//'\d'//labelcoord(i,1) |
| 348 |
enddo |
| 349 |
endif |
| 350 |
if (iBfirst > 0) then |
| 351 |
iamvec(iBfirst:iBfirst+ndimV-1) = iBfirst |
| 352 |
labelvec(iBfirst:iBfirst+ndimV-1) = 'B' |
| 353 |
endif |
| 354 |
! |
| 355 |
!--set labels for each type of particles |
| 356 |
! |
| 357 |
labeltype(1) = 'gas' |
| 358 |
UseTypeInRenderings(1) = .true. |
| 359 |
if (ntypes >= 2) then |
| 360 |
labeltype(2) = 'auxiliary' |
| 361 |
UseTypeInRenderings(2) = .true. |
| 362 |
endif |
| 363 |
if (ntypes >= 3) then |
| 364 |
labeltype(3) = 'mirror' |
| 365 |
UseTypeInRenderings(3) = .true. |
| 366 |
endif |
| 367 |
|
| 368 |
!----------------------------------------------------------- |
| 369 |
|
| 370 |
return |
| 371 |
end subroutine set_labels_rsph |
| 372 |
end module readdata_rsph |