| 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 DATA FORMATS WRITTEN WITH THE H5PART LIBRARY |
| 28 |
! |
| 29 |
! Some choices for this format can be set using the following |
| 30 |
! command-line flags or environment variables: |
| 31 |
! |
| 32 |
! --ndim=2 or H5SPLASH_NDIM=2 : number of spatial dimensions (overrides value inferred from data) |
| 33 |
! --hfac=1.2 or H5SPLASH_HFAC=1.2 : factor to use in h= hfac*(m/rho)**(1/ndim) if h not present in data |
| 34 |
! --hsml=1.0 or H5SPLASH_HSML=1.0 : value for global smoothing length if h not present in data |
| 35 |
! --typeid=MatID or H5SPLASH_TYPEID='MatID' : name of dataset containing the particle types |
| 36 |
! |
| 37 |
! the data is stored in the global array dat |
| 38 |
! |
| 39 |
! >> this subroutine must return values for the following: << |
| 40 |
! |
| 41 |
! ncolumns : number of data columns |
| 42 |
! ndim, ndimV : number of spatial, velocity dimensions |
| 43 |
! nstepsread : number of steps read from this file |
| 44 |
! |
| 45 |
! dat(maxplot,maxpart,maxstep) : main data array |
| 46 |
! |
| 47 |
! npartoftype(1:6,maxstep) : number of particles of each type in each timestep |
| 48 |
! ntot(maxstep) : total number of particles in each timestep |
| 49 |
! |
| 50 |
! time(maxstep) : time at each step |
| 51 |
! gamma(maxstep) : gamma at each step |
| 52 |
! |
| 53 |
! most of these values are stored in global arrays |
| 54 |
! in the module 'particle_data' |
| 55 |
!------------------------------------------------------------------------- |
| 56 |
|
| 57 |
!--local module to store header information so we can later set the labels |
| 58 |
module h5partdataread |
| 59 |
use params |
| 60 |
use labels, only:lenlabel |
| 61 |
implicit none |
| 62 |
character(len=lenlabel), dimension(maxplot) :: datasetnames |
| 63 |
logical :: warn_labels = .true. |
| 64 |
|
| 65 |
end module h5partdataread |
| 66 |
|
| 67 |
module readdata_h5part |
| 68 |
implicit none |
| 69 |
|
| 70 |
public :: read_data_h5part, set_labels_h5part |
| 71 |
|
| 72 |
private |
| 73 |
contains |
| 74 |
|
| 75 |
subroutine read_data_h5part(rootname,indexstart,ipos,nstepsread) |
| 76 |
use particle_data, only:dat,iamtype,npartoftype,time,gamma,maxpart,maxcol,maxstep |
| 77 |
use params |
| 78 |
use settings_data, only:ndim,ndimV,ncolumns,ncalc,debugmode,ntypes,iverbose |
| 79 |
use mem_allocation, only:alloc |
| 80 |
use iso_c_binding, only:c_double,c_int64_t |
| 81 |
use asciiutils, only:lcase |
| 82 |
use system_utils, only:renvironment,get_environment_or_flag |
| 83 |
use labels, only:ih,ipmass,irho,ix |
| 84 |
use h5part |
| 85 |
use h5partattrib, only:h5pt_readstepattrib,h5pt_getnstepattribs,h5pt_getstepattribinfo, & |
| 86 |
h5pt_readstepattrib_r8, h5pt_readstepattrib_string |
| 87 |
use h5partdataread |
| 88 |
integer, intent(in) :: indexstart,ipos |
| 89 |
integer, intent(out) :: nstepsread |
| 90 |
character(len=*), intent(in) :: rootname |
| 91 |
integer :: i,j,ncolstep,nsteps,ncolsfile,icol,itypeidcol |
| 92 |
integer(kind=c_int64_t) :: nattrib,iattrib,nelem,idatasettype,k,icolsfile,ierr |
| 93 |
integer :: nprint,npart_max,nstep_max,maxcolsfile,itype |
| 94 |
integer, dimension(maxplot) :: iorder |
| 95 |
integer, dimension(maxparttypes) :: itypemap |
| 96 |
integer, dimension(:),allocatable :: itypefile |
| 97 |
logical :: iexist,typeiddefault |
| 98 |
integer(kind=c_int64_t) :: ifile,istep |
| 99 |
character(len=len(rootname)+5) :: dumpfile |
| 100 |
character(len=64) :: attribname |
| 101 |
character(len=lenlabel) :: datasetname,type_datasetname |
| 102 |
real(kind=doub_prec),dimension(1) :: dtime |
| 103 |
real :: hsmooth,hfac,dndim |
| 104 |
character(len=64) :: xstring |
| 105 |
|
| 106 |
nstepsread = 0 |
| 107 |
nstep_max = 0 |
| 108 |
npart_max = maxpart |
| 109 |
|
| 110 |
dumpfile = trim(rootname) |
| 111 |
|
| 112 |
if (iverbose >= 1) print "(1x,a)",'reading h5part format' |
| 113 |
print "(26('>'),1x,a,1x,26('<'))",trim(dumpfile) |
| 114 |
! |
| 115 |
!--check if first data file exists |
| 116 |
! |
| 117 |
inquire(file=dumpfile,exist=iexist) |
| 118 |
if (.not.iexist) then |
| 119 |
print "(a)",' *** error: '//trim(dumpfile)//': file not found ***' |
| 120 |
return |
| 121 |
endif |
| 122 |
! |
| 123 |
!--fix number of spatial dimensions (0 means no particle coords) |
| 124 |
! |
| 125 |
ndim = 0 |
| 126 |
ndimV = 0 |
| 127 |
j = indexstart |
| 128 |
nstepsread = 0 |
| 129 |
|
| 130 |
! |
| 131 |
!--open the file and read the number of particles |
| 132 |
! |
| 133 |
if (debugmode) print*,'DEBUG: opening '//trim(dumpfile) |
| 134 |
!ierr = h5pt_set_verbosity_level(6_8) |
| 135 |
|
| 136 |
ifile = h5pt_openr(trim(dumpfile)) |
| 137 |
if (ifile <= 0) then |
| 138 |
print "(a)",'*** ERROR opening '//trim(dumpfile)//' ***' |
| 139 |
return |
| 140 |
endif |
| 141 |
if (debugmode) print*,'DEBUG: file opened ok' |
| 142 |
|
| 143 |
! |
| 144 |
!--get number of steps and particles in the file |
| 145 |
! |
| 146 |
nsteps = int(h5pt_getnsteps(ifile)) |
| 147 |
if (debugmode) print*,'DEBUG: nsteps = ',nsteps |
| 148 |
|
| 149 |
! |
| 150 |
!--read environment variable giving the name of the dataset |
| 151 |
! containing the particle type ID |
| 152 |
! give default value if this is not set |
| 153 |
! |
| 154 |
call get_environment_or_flag('H5SPLASH_TYPEID',type_datasetname) |
| 155 |
if (len_trim(type_datasetname) <= 0) then |
| 156 |
typeiddefault = .true. |
| 157 |
type_datasetname = 'MatID' |
| 158 |
else |
| 159 |
typeiddefault = .false. |
| 160 |
endif |
| 161 |
! |
| 162 |
!--read "header" information from all steps in file: |
| 163 |
! get maximum number of particles for all steps in file |
| 164 |
! and maximum number of columns (datasets) in file |
| 165 |
! |
| 166 |
npart_max = 0 |
| 167 |
ncolstep = 0 |
| 168 |
maxcolsfile = 0 |
| 169 |
itypeidcol = 0 |
| 170 |
do istep=1,nsteps |
| 171 |
if (debugmode) print "(a,i2)",'DEBUG: setting step ',istep |
| 172 |
ierr = h5pt_setstep(ifile,istep) |
| 173 |
if (ierr==0) then |
| 174 |
npart_max = max(npart_max,int(h5pt_getnpoints(ifile))) |
| 175 |
ncolsfile = int(h5pt_getndatasets(ifile)) |
| 176 |
icol = 0 |
| 177 |
if ((istep==nsteps .and. ncolsfile > 0)) then |
| 178 |
do icolsfile=0,ncolsfile-1 |
| 179 |
!ierr = h5pt_getdatasetname(ifile,icol,datasetnames(icol+1)) |
| 180 |
if (debugmode) print*,'DEBUG: getting datasetinfo' |
| 181 |
ierr = h5pt_getdatasetinfo(ifile,icolsfile,datasetname,idatasettype,nelem) |
| 182 |
if (ierr /= 0) then |
| 183 |
print "(a,i3)",' ERROR reading dataset name for column ',icolsfile+1 |
| 184 |
else |
| 185 |
! |
| 186 |
!--read only columns which contain real or double precision data |
| 187 |
! |
| 188 |
select case(idatasettype) |
| 189 |
case(H5PART_FLOAT32,H5PART_FLOAT64) |
| 190 |
icol = icol + 1 |
| 191 |
datasetnames(icol) = trim(adjustl(datasetname)) |
| 192 |
!print*,' data set info = ',icol,trim(datasetnames(icol)),idatasettype,nelem |
| 193 |
case(H5PART_INT32,H5PART_INT64) |
| 194 |
! |
| 195 |
!--try to recognise the dataset giving the particle types |
| 196 |
! |
| 197 |
if (trim(type_datasetname)==trim(datasetname) .or. trim(datasetname)=='Phase') then |
| 198 |
type_datasetname = trim(datasetname) |
| 199 |
if (itypeidcol <= 0) itypeidcol = int(icolsfile) + 1 |
| 200 |
if (iverbose >= 1) print "(a)",' getting particle types from data set '//trim(type_datasetname) |
| 201 |
else |
| 202 |
if (iverbose >= 1) print "(a)",' skipping data set '//trim(datasetname)// & |
| 203 |
' of type '//h5part_type(int(idatasettype)) |
| 204 |
endif |
| 205 |
case default |
| 206 |
if (iverbose >= 1) print "(a)",' skipping data set '//trim(datasetname)//& |
| 207 |
' of type '//h5part_type(int(idatasettype)) |
| 208 |
end select |
| 209 |
endif |
| 210 |
enddo |
| 211 |
elseif (ncolsfile <= 0) then |
| 212 |
print*,'ERROR: number of datasets in step ',istep,' = ',ncolsfile |
| 213 |
endif |
| 214 |
ncolstep = max(ncolstep,icol) |
| 215 |
maxcolsfile = max(ncolsfile,maxcolsfile) |
| 216 |
else |
| 217 |
print "(a,i3)",' ERROR, could not choose step ',istep |
| 218 |
return |
| 219 |
endif |
| 220 |
enddo |
| 221 |
nprint = npart_max |
| 222 |
|
| 223 |
! |
| 224 |
!--warn if no particle type data has been read |
| 225 |
! |
| 226 |
if (itypeidcol <= 0) then |
| 227 |
if (typeiddefault) then |
| 228 |
if (iverbose >= 1) print "(a)",' Particle type dataset not found in file: Use --typeid=blah to give dataset name' |
| 229 |
else |
| 230 |
print "(a)",' WARNING: Particle type dataset '//trim(type_datasetname)//' (from --typeid) not found in file ' |
| 231 |
endif |
| 232 |
endif |
| 233 |
|
| 234 |
! |
| 235 |
!--call the set_labels_h5part routine to get the initial location of coords, smoothing length etc. given dataset labels |
| 236 |
! |
| 237 |
warn_labels = .false. |
| 238 |
call set_labels_h5part() |
| 239 |
warn_labels = .true. |
| 240 |
|
| 241 |
! |
| 242 |
!--set default ordering of columns |
| 243 |
! |
| 244 |
do i=1,size(iorder) |
| 245 |
iorder(i) = i |
| 246 |
enddo |
| 247 |
! |
| 248 |
!--if coordinates are not in the first 3 columns, shift data so that they are |
| 249 |
! |
| 250 |
|
| 251 |
if (ndim > 0 .and. ix(1) /= 1) then |
| 252 |
do i=1,ndim |
| 253 |
iorder(ix(i)) = i |
| 254 |
enddo |
| 255 |
!--preserve the order of things after the coordinates |
| 256 |
icol = ndim |
| 257 |
do i=ix(1)+1,ncolstep |
| 258 |
if (.not.any(ix(1:ndim)==i)) then |
| 259 |
icol = icol + 1 |
| 260 |
iorder(i) = icol |
| 261 |
endif |
| 262 |
enddo |
| 263 |
!--shuffle things before the coordinates to the end |
| 264 |
do i=1,ix(1)-1 |
| 265 |
if (.not.any(ix(1:ndim)==i)) then |
| 266 |
icol = icol + 1 |
| 267 |
iorder(i) = icol |
| 268 |
endif |
| 269 |
enddo |
| 270 |
endif |
| 271 |
if (debugmode) print*,'DEBUG: iorder = ',iorder |
| 272 |
|
| 273 |
! |
| 274 |
!--if smoothing length has not been set, look for an environment variable |
| 275 |
! giving the smoothing length value |
| 276 |
! |
| 277 |
hsmooth = -1. |
| 278 |
if (ih==0) then |
| 279 |
hsmooth = renvironment('H5SPLASH_HSML',errval=-1.) |
| 280 |
if (hsmooth >= 0.) then |
| 281 |
ncolstep = ncolstep + 1 |
| 282 |
elseif (ipmass > 0. .and. irho > 0 .and. ndim > 0) then |
| 283 |
hfac = renvironment('H5SPLASH_HFAC',errval=-1.) |
| 284 |
if (hfac > 0.) then |
| 285 |
if (iverbose >= 1) print "(/,a,f6.2,a,/)",' Setting smoothing length using h = ',hfac,& |
| 286 |
'*(m/rho)**(1/ndim) (from --hfac setting)' |
| 287 |
else |
| 288 |
hfac = 1.2 |
| 289 |
if (iverbose >= 1) then |
| 290 |
print "(/,a)",' WARNING: Smoothing length not found in data: using h = hfac*(m/rho)**(1/ndim)' |
| 291 |
print "(a)", ' (hfac = 1.2 by default, set e.g. --hfac=1.5 to change this)' |
| 292 |
print "(a,/)",' (set constant h with --hsml=1.0 to give a global value)' |
| 293 |
endif |
| 294 |
endif |
| 295 |
ncolstep = ncolstep + 1 |
| 296 |
else |
| 297 |
if (iverbose >= 1) print "(/,a,/)",' WARNING: Smoothing length not found in data: Set --hsml to give a global value' |
| 298 |
endif |
| 299 |
endif |
| 300 |
ncolumns = ncolstep |
| 301 |
|
| 302 |
! |
| 303 |
!--allocate memory for all data in the file |
| 304 |
! |
| 305 |
nstep_max = max(nsteps,indexstart,1,maxstep) |
| 306 |
npart_max = max(maxpart,npart_max) |
| 307 |
if (.not.allocated(dat) .or. (nprint > maxpart) .or. (ncolstep+ncalc) > maxcol) then |
| 308 |
if (itypeidcol > 0) then |
| 309 |
call alloc(npart_max,nstep_max,ncolstep+ncalc,mixedtypes=.true.) |
| 310 |
else |
| 311 |
call alloc(npart_max,nstep_max,ncolstep+ncalc) |
| 312 |
endif |
| 313 |
endif |
| 314 |
|
| 315 |
! |
| 316 |
!--now read the timestep data in the dumpfile (for all steps) |
| 317 |
! |
| 318 |
istep = 0 |
| 319 |
do j=indexstart,indexstart+nsteps-1 |
| 320 |
istep = istep + 1 |
| 321 |
print "(a,i4,a,i10)",' step ',istep,': ntotal = ',nprint |
| 322 |
ierr = h5pt_setstep(ifile,istep) |
| 323 |
nprint = int(h5pt_getnpoints(ifile)) ! use int() to avoid compiler warning about type conversion |
| 324 |
! |
| 325 |
!--get the time from the step attributes |
| 326 |
! |
| 327 |
nattrib = h5pt_getnstepattribs(ifile) |
| 328 |
if (nattrib > 0) then |
| 329 |
do iattrib=0,nattrib-1 ! yes, it's written in C |
| 330 |
ierr = h5pt_getstepattribinfo(ifile,iattrib,attribname,nelem) |
| 331 |
!print*,' step attribute '//trim(attribname),' nelem = ',nelem |
| 332 |
if (ierr==0) then |
| 333 |
! |
| 334 |
!--match anything that looks vaguely like the time |
| 335 |
! |
| 336 |
if (nelem==1 .and. (index(lcase(attribname),'time') /= 0 & |
| 337 |
.or. index(lcase(attribname),'t ') /= 0)) then |
| 338 |
ierr = h5pt_readstepattrib_string(ifile,attribname,xstring) |
| 339 |
if (ierr==0) then |
| 340 |
read(xstring,'(f10.0)') time(j) |
| 341 |
print "(12x,a,es10.3,a)",'time = ',time(j),' (from '//trim(attribname)//')' |
| 342 |
else |
| 343 |
print "(a,i2,a)",' ERROR could not read time from step ',istep,' (from '//trim(attribname)//')' |
| 344 |
endif |
| 345 |
! |
| 346 |
!--match gamma if possible |
| 347 |
! |
| 348 |
elseif (nelem==1 .and. (index(lcase(attribname),'gamma') /= 0 & |
| 349 |
.or. index(lcase(attribname),'gam ') /= 0)) then |
| 350 |
ierr = h5pt_readstepattrib_string(ifile,attribname,xstring) |
| 351 |
|
| 352 |
if (ierr==0) then |
| 353 |
gamma(j) = real(dtime(1)) |
| 354 |
print "(12x,a,es10.3,a)",'gamma = ',gamma(j),' (from '//trim(attribname)//')' |
| 355 |
else |
| 356 |
print "(a,i2,a)",' ERROR could not read gamma from step ',istep,' (from '//trim(attribname)//')' |
| 357 |
endif |
| 358 |
else |
| 359 |
print "(a)",' unknown attribute '//trim(attribname) |
| 360 |
endif |
| 361 |
else |
| 362 |
print "(a,i3,a,i2)",' ERROR reading attribute info for step ',istep,', attribute #',iattrib |
| 363 |
endif |
| 364 |
enddo |
| 365 |
endif |
| 366 |
! |
| 367 |
!--now read the data for this step |
| 368 |
! |
| 369 |
icol = 0 |
| 370 |
do k=0,maxcolsfile-1 |
| 371 |
ierr = h5pt_getdatasetinfo(ifile,k,datasetname,idatasettype,nelem) |
| 372 |
select case(idatasettype) |
| 373 |
case(H5PART_FLOAT32,H5PART_FLOAT64) |
| 374 |
icol = icol + 1 |
| 375 |
datasetnames(iorder(icol)) = trim(datasetname) |
| 376 |
if (debugmode) print "(a,i3,a,i3)",'DEBUG: reading data set ',icol,& |
| 377 |
': '//trim(datasetnames(iorder(icol)))//' into column ',iorder(icol) |
| 378 |
ierr = h5pt_readdata(ifile,datasetnames(iorder(icol)),dat(:,iorder(icol),j)) |
| 379 |
if (ierr /= 0) print "(a)",' ERROR reading dataset '//trim(datasetnames(iorder(icol))) |
| 380 |
case default |
| 381 |
if (debugmode) print "(a)",' skipping data set '//trim(datasetname)//' of type '//lcase(h5part_type(int(idatasettype))) |
| 382 |
end select |
| 383 |
enddo |
| 384 |
! |
| 385 |
!--read the particle types for this step from the typeid dataset (specified from the type_datasetname setting) |
| 386 |
! |
| 387 |
npartoftype(:,j) = 0 |
| 388 |
if (itypeidcol > 0 .and. size(iamtype(:,1)) > 1) then |
| 389 |
if (debugmode) print "(a)",'DEBUG: reading particle types from '//trim(type_datasetname) |
| 390 |
! |
| 391 |
!--allocate temporary memory |
| 392 |
! |
| 393 |
if (allocated(itypefile)) deallocate(itypefile) |
| 394 |
allocate(itypefile(nprint),stat=ierr) |
| 395 |
if (ierr /= 0) stop 'ERROR allocating temporary memory for particle types' |
| 396 |
! |
| 397 |
!--read type array from file |
| 398 |
! |
| 399 |
ierr = h5pt_readdata(ifile,trim(type_datasetname),itypefile(:)) |
| 400 |
if (ierr /= 0) then |
| 401 |
print "(a)",' ERROR reading dataset '//trim(type_datasetname) |
| 402 |
else |
| 403 |
! |
| 404 |
!--work out the number of unique particle types |
| 405 |
! and map these into SPLASH particle types (1->maxtypes) |
| 406 |
! |
| 407 |
if (j==1 .and. istep==1) then |
| 408 |
ntypes = 1 |
| 409 |
itypemap(1) = minval(itypefile) |
| 410 |
endif |
| 411 |
do i=1,nprint |
| 412 |
!--increase the number of particle types if a particle of new type is found |
| 413 |
if (.not.any(itypemap(1:ntypes)==itypefile(i))) then |
| 414 |
ntypes = ntypes + 1 |
| 415 |
if (ntypes <= size(itypemap)) then |
| 416 |
itypemap(ntypes) = itypefile(i) |
| 417 |
npartoftype(ntypes,j) = npartoftype(ntypes,j) + 1 |
| 418 |
iamtype(i,j) = ntypes |
| 419 |
endif |
| 420 |
else |
| 421 |
do itype=1,ntypes |
| 422 |
if (itypefile(i)==itypemap(itype)) then |
| 423 |
npartoftype(itype,j) = npartoftype(itype,j) + 1 |
| 424 |
iamtype(i,j) = itype |
| 425 |
endif |
| 426 |
enddo |
| 427 |
endif |
| 428 |
enddo |
| 429 |
if (nprint < 1e6) then |
| 430 |
print "(12x,a,10(i5,1x))",'npart (by type) = ',npartoftype(1:ntypes,j) |
| 431 |
else |
| 432 |
print "(12x,a,10(i10,1x))",'npart (by type) = ',npartoftype(1:ntypes,j) |
| 433 |
endif |
| 434 |
! |
| 435 |
!--warn if the number of types exceeds the current limit |
| 436 |
! |
| 437 |
if (ntypes > maxparttypes) & |
| 438 |
print "(/,2(a,i2),a/)", & |
| 439 |
' WARNING: too many particle types in dataset '//trim(type_datasetname)// & |
| 440 |
' (got ',ntypes,': maximum is currently ',maxparttypes,')' |
| 441 |
endif |
| 442 |
! |
| 443 |
!--clean up |
| 444 |
! |
| 445 |
if (allocated(itypefile)) deallocate(itypefile) |
| 446 |
else |
| 447 |
!--only one particle type |
| 448 |
ntypes = 1 |
| 449 |
npartoftype(1,j) = nprint |
| 450 |
endif |
| 451 |
! |
| 452 |
!--reset the labels now that the columns have been read in the correct order |
| 453 |
! |
| 454 |
if (j==indexstart) then ! set labels based on the first step read from the file |
| 455 |
warn_labels = .false. |
| 456 |
call set_labels_h5part() |
| 457 |
warn_labels = .true. |
| 458 |
endif |
| 459 |
! |
| 460 |
!--if smoothing length set via environment variable, fill the extra column with the smoothing length value |
| 461 |
! |
| 462 |
if (ih==0) then |
| 463 |
if (hsmooth >= 0.) then |
| 464 |
datasetnames(ncolstep) = 'h' |
| 465 |
ih = ncolstep |
| 466 |
dat(:,ih,j) = hsmooth |
| 467 |
elseif (ipmass > 0 .and. irho > 0 .and. ndim > 0) then |
| 468 |
ih = ncolstep |
| 469 |
datasetnames(ncolstep) = 'h' |
| 470 |
dndim = 1./ndim |
| 471 |
where (dat(:,irho,j) > tiny(0.)) |
| 472 |
dat(:,ih,j) = hfac*(dat(:,ipmass,j)/dat(:,irho,j))**dndim |
| 473 |
elsewhere |
| 474 |
dat(:,ih,j) = 0. |
| 475 |
end where |
| 476 |
endif |
| 477 |
endif |
| 478 |
! read(iunit,*,iostat=ierr) (dat(i,icol,j),icol = 1,ncolstep) |
| 479 |
nstepsread = nstepsread + 1 |
| 480 |
enddo |
| 481 |
|
| 482 |
ierr = h5pt_close(ifile) |
| 483 |
|
| 484 |
return |
| 485 |
end subroutine read_data_h5part |
| 486 |
|
| 487 |
!!------------------------------------------------------------------- |
| 488 |
!! set labels for each column of data |
| 489 |
!! |
| 490 |
!! read these from a file called 'columns' in the current directory |
| 491 |
!! then take sensible guesses as to which quantities are which |
| 492 |
!! from the column labels |
| 493 |
!! |
| 494 |
!!------------------------------------------------------------------- |
| 495 |
|
| 496 |
subroutine set_labels_h5part() |
| 497 |
use asciiutils, only:lcase |
| 498 |
use labels, only:label,ix,irho,ipmass,ih,iutherm, & |
| 499 |
ipr,ivx,iBfirst,iamvec,labelvec,lenlabel !,labeltype |
| 500 |
!use params, only:maxparttypes |
| 501 |
use settings_data, only:ndim,ndimV,UseTypeInRenderings,iverbose |
| 502 |
use geometry, only:labelcoord |
| 503 |
use system_utils, only:ienvironment |
| 504 |
use h5partdataread |
| 505 |
integer :: i,ndimset,ndim_max |
| 506 |
character(len=lenlabel) :: labeli |
| 507 |
|
| 508 |
ndim = 0 |
| 509 |
ndimV = 0 |
| 510 |
ndimset = ienvironment('H5SPLASH_NDIM',errval=-1) |
| 511 |
ndim_max = 3 |
| 512 |
if (ndimset >= 0) ndim_max = ndimset |
| 513 |
irho = 0 |
| 514 |
ih = 0 |
| 515 |
ipmass = 0 |
| 516 |
|
| 517 |
do i=1,size(datasetnames) |
| 518 |
if (len_trim(datasetnames(i)) > 0) then |
| 519 |
label(i) = trim(datasetnames(i)) |
| 520 |
else |
| 521 |
label(i) = ' ' |
| 522 |
endif |
| 523 |
!--now try to recognise the column based on the dataset name |
| 524 |
! compare all strings in lower case, trimmed and with no preceding spaces |
| 525 |
! |
| 526 |
labeli = trim(adjustl(lcase(label(i)))) |
| 527 |
if (index(labeli,'coords') /= 0 .and. index(labeli,'_') /= 0 .or. labeli(1:1)=='x') then |
| 528 |
if (ndim < ndim_max) then |
| 529 |
ndim = ndim + 1 |
| 530 |
ix(ndim) = i |
| 531 |
label(ix(ndim)) = labelcoord(ndim,1) |
| 532 |
endif |
| 533 |
elseif (index(labeli,'vel_') /= 0 .and. (ivx==0 .or. i <= ivx+ndim)) then |
| 534 |
if (ndimV < 3) ndimV = ndimV + 1 |
| 535 |
if (index(labeli,'_0') /= 0) ivx = i |
| 536 |
elseif (index(labeli,'dens') /= 0 .and. irho==0) then |
| 537 |
irho = i |
| 538 |
elseif (index(labeli,'mass') /= 0 .and. ipmass==0) then |
| 539 |
ipmass = i |
| 540 |
elseif (ih==0 .and. (index(labeli,'smoothing') /= 0 .or. labeli(1:1)=='h')) then |
| 541 |
ih = i |
| 542 |
elseif (labeli(1:1)=='u') then |
| 543 |
iutherm = i |
| 544 |
!--identify vector quantities based on _0, _1, _2 labelling |
| 545 |
elseif (index(labeli,'_0') /= 0) then |
| 546 |
!print*,'labelling ',labeli(1:index(labeli,'_0')-1),' as vector, column ',i |
| 547 |
iamvec(i) = i |
| 548 |
labelvec(i) = labeli(1:index(labeli,'_0')-1) |
| 549 |
elseif (index(labeli,'_1') /= 0 .and. i > 1 .and. ndim >= 2) then |
| 550 |
if (iamvec(i-1) > 0) then |
| 551 |
iamvec(i) = i-1 |
| 552 |
labelvec(i) = labelvec(i-1) |
| 553 |
endif |
| 554 |
elseif (index(labeli,'_2') /= 0 .and. i > 2 .and. ndim >= 3) then |
| 555 |
if (iamvec(i-2) > 0) then |
| 556 |
iamvec(i) = i-2 |
| 557 |
labelvec(i) = labelvec(i-2) |
| 558 |
endif |
| 559 |
endif |
| 560 |
enddo |
| 561 |
|
| 562 |
if (ndim < 1) ndimV = 0 |
| 563 |
if (ndimV > ndim) ndimV = ndim |
| 564 |
|
| 565 |
if (warn_labels .and. iverbose >= 1) then |
| 566 |
if (ndimset > 0) then |
| 567 |
if (ndim /= ndimset) then |
| 568 |
print "(2(a,i1))",' WARNING: ndim = ',ndimset, & |
| 569 |
' from --ndim setting but coords not found in data: using ndim = ',ndim |
| 570 |
else |
| 571 |
print "(a,i1,a)",' Assuming number of dimensions = ',ndim,' from --ndim setting' |
| 572 |
endif |
| 573 |
else |
| 574 |
if (ndim > 0) print "(a,i1,a)",' Assuming number of dimensions = ',ndim,' (set --ndim=3 to override)' |
| 575 |
endif |
| 576 |
|
| 577 |
if (ndimV > 0) print "(a,i1)",' Assuming vectors have dimension = ',ndimV |
| 578 |
if (irho > 0) print "(a,i2)",' Assuming density in column ',irho |
| 579 |
if (ipmass > 0) print "(a,i2)",' Assuming particle mass in column ',ipmass |
| 580 |
if (ih > 0) print "(a,i2)",' Assuming smoothing length in column ',ih |
| 581 |
if (iutherm > 0) print "(a,i2)",' Assuming thermal energy in column ',iutherm |
| 582 |
if (ipr > 0) print "(a,i2)",' Assuming pressure in column ',ipr |
| 583 |
if (ivx > 0) then |
| 584 |
if (ndimV > 1) then |
| 585 |
print "(a,i2,a,i2)",' Assuming velocity in columns ',ivx,' to ',ivx+ndimV-1 |
| 586 |
else |
| 587 |
print "(a,i2)",' Assuming velocity in column ',ivx |
| 588 |
endif |
| 589 |
endif |
| 590 |
if (ndim==0 .or. irho==0 .or. ipmass==0 .or. ih==0) then |
| 591 |
print "(4(/,a))",' NOTE: Rendering capabilities cannot be enabled', & |
| 592 |
' until positions of density, smoothing length and particle', & |
| 593 |
' mass are known (for the h5part read this means labelling ', & |
| 594 |
' the dataset appropriately)' |
| 595 |
endif |
| 596 |
|
| 597 |
! |
| 598 |
!--assign vectors (don't do this on the first call otherwise it will remain assigned to the wrong columns) |
| 599 |
! |
| 600 |
if (ivx > 0) then |
| 601 |
iamvec(ivx:ivx+ndimV-1) = ivx |
| 602 |
labelvec(ivx:ivx+ndimV-1) = 'v' |
| 603 |
endif |
| 604 |
if (iBfirst > 0) then |
| 605 |
iamvec(iBfirst:iBfirst+ndimV-1) = ivx |
| 606 |
labelvec(iBfirst:iBfirst+ndimV-1) = 'B' |
| 607 |
endif |
| 608 |
|
| 609 |
! |
| 610 |
!--set labels for vector quantities |
| 611 |
! |
| 612 |
do i=1,size(datasetnames) |
| 613 |
if (iamvec(i) /= 0) then |
| 614 |
label(i) = trim(labelvec(iamvec(i)))//'_'//trim(labelcoord(i-iamvec(i)+1,1)) |
| 615 |
endif |
| 616 |
enddo |
| 617 |
endif |
| 618 |
! |
| 619 |
!--set labels for each particle type |
| 620 |
! (for h5part this is done in the read_data_h5part routine) |
| 621 |
! |
| 622 |
|
| 623 |
!ntypes = 1 !!maxparttypes |
| 624 |
! labeltype(1) = 'gas' |
| 625 |
! labeltype(2) = 'gas' |
| 626 |
! labeltype(3) = 'gas' |
| 627 |
! labeltype(4) = 'gas' |
| 628 |
UseTypeInRenderings(:) = .true. |
| 629 |
|
| 630 |
|
| 631 |
!----------------------------------------------------------- |
| 632 |
|
| 633 |
return |
| 634 |
end subroutine set_labels_h5part |
| 635 |
end module readdata_h5part |