| 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 READING UNFORMATTED OUTPUT FROM ANDREA URBAN'S CODE |
| 28 |
! (ie. STRAIGHT FROM THE DATA DUMP) |
| 29 |
! |
| 30 |
! the data is stored in the global array dat |
| 31 |
! |
| 32 |
! >> this subroutine must return values for the following: << |
| 33 |
! |
| 34 |
! ncolumns : number of data columns |
| 35 |
! ndim, ndimV : number of spatial, velocity dimensions |
| 36 |
! nstepsread : number of steps read from this file |
| 37 |
! |
| 38 |
! maxplot,maxpart,maxstep : dimensions of main data array |
| 39 |
! dat(maxplot,maxpart,maxstep) : main data array |
| 40 |
! |
| 41 |
! npartoftype(1:6,maxstep) : number of particles of each type in each timestep |
| 42 |
! |
| 43 |
! time(maxstep) : time at each step |
| 44 |
! gamma(maxstep) : gamma at each step |
| 45 |
! |
| 46 |
! most of these values are stored in global arrays |
| 47 |
! in the module 'particle_data' |
| 48 |
!------------------------------------------------------------------------- |
| 49 |
|
| 50 |
module readdata_urban |
| 51 |
implicit none |
| 52 |
|
| 53 |
public :: read_data_urban, set_labels_urban |
| 54 |
|
| 55 |
private |
| 56 |
contains |
| 57 |
|
| 58 |
subroutine read_data_urban(rootname,indexstart,ipos,nstepsread) |
| 59 |
use particle_data, only:dat,npartoftype,maxpart,maxcol,maxstep,time,gamma |
| 60 |
use params |
| 61 |
use settings_data, only:ndim,ndimV,ncolumns,ncalc |
| 62 |
use mem_allocation, only:alloc |
| 63 |
!use system_utils, only:lenvironment,ienvironment |
| 64 |
use asciiutils, only:get_ncolumns |
| 65 |
integer, intent(in) :: indexstart,ipos |
| 66 |
integer, intent(out) :: nstepsread |
| 67 |
character(len=*), intent(in) :: rootname |
| 68 |
integer :: i,j,ierr,lab,icol,ilen |
| 69 |
integer :: nprint,npart_max,nstep_max |
| 70 |
integer :: ncol,nerr,nheaderlines |
| 71 |
logical :: iexist,timeset,gammaset |
| 72 |
real :: dummyreal |
| 73 |
character(len=len(rootname)+5) :: dumpfile |
| 74 |
integer, parameter :: iunit = 15 |
| 75 |
|
| 76 |
nstepsread = 0 |
| 77 |
nstep_max = 0 |
| 78 |
npart_max = maxpart |
| 79 |
dumpfile = trim(rootname) |
| 80 |
! |
| 81 |
!--check if first data file exists |
| 82 |
! |
| 83 |
inquire(file=dumpfile,exist=iexist) |
| 84 |
if (.not.iexist) then |
| 85 |
print "(a)",' *** error: '//trim(dumpfile)//': file not found ***' |
| 86 |
return |
| 87 |
endif |
| 88 |
! |
| 89 |
!--fix number of spatial dimensions |
| 90 |
! |
| 91 |
ndim = 3 |
| 92 |
ndimV = 3 |
| 93 |
|
| 94 |
!--number of columns to read from file |
| 95 |
! this is determined automatically |
| 96 |
!ncol = 13 |
| 97 |
|
| 98 |
j = indexstart |
| 99 |
nstepsread = 0 |
| 100 |
print "(a)",' reading Andrea Urban ascii file format' |
| 101 |
|
| 102 |
write(*,"(26('>'),1x,a,1x,26('<'))") trim(dumpfile) |
| 103 |
! |
| 104 |
!--open the file and read the number of particles |
| 105 |
! |
| 106 |
open(unit=iunit,file=dumpfile,status='old',form='formatted',iostat=ierr) |
| 107 |
if (ierr /= 0) then |
| 108 |
print "(a)",'*** ERROR OPENING '//trim(dumpfile)//' ***' |
| 109 |
return |
| 110 |
else |
| 111 |
call get_ncolumns(iunit,ncol,nheaderlines) |
| 112 |
ncol = max(ncol - 1,0) |
| 113 |
if (ncol <= 0) then |
| 114 |
print "(a,/)",' *** no data read from file ***' |
| 115 |
return |
| 116 |
endif |
| 117 |
! |
| 118 |
!--allocate memory initially |
| 119 |
! |
| 120 |
nprint = 10001 |
| 121 |
nstep_max = max(nstep_max,indexstart,1) |
| 122 |
if (.not.allocated(dat) .or. (nprint > npart_max) .or. (ncol+ncalc) > maxcol) then |
| 123 |
npart_max = max(npart_max,nprint) |
| 124 |
call alloc(npart_max,nstep_max,ncol+ncalc) |
| 125 |
endif |
| 126 |
endif |
| 127 |
|
| 128 |
npart_max = max(npart_max,nprint) |
| 129 |
ncolumns = ncol |
| 130 |
! |
| 131 |
!--allocate/reallocate memory if j > maxstep |
| 132 |
! |
| 133 |
if (j > maxstep) then |
| 134 |
call alloc(maxpart,j+1,maxcol) |
| 135 |
endif |
| 136 |
|
| 137 |
! |
| 138 |
!--read header lines, try to use it to set time |
| 139 |
! |
| 140 |
timeset = .false. |
| 141 |
gammaset = .false. |
| 142 |
|
| 143 |
if (nheaderlines > 0) then |
| 144 |
print*,'skipping ',nheaderlines,' header lines' |
| 145 |
do i=1,nheaderlines |
| 146 |
read(iunit,*,iostat=ierr) dummyreal |
| 147 |
if (timeset .and. .not.gammaset .and. ierr==0 & |
| 148 |
.and. dummyreal > 0.999999 .and. dummyreal < 2.000001) then |
| 149 |
print*,'setting gamma = ',dummyreal,' from header line ',i |
| 150 |
gamma(j) = dummyreal |
| 151 |
gammaset = .true. |
| 152 |
endif |
| 153 |
if (ierr==0 .and. .not. timeset) then |
| 154 |
time(j) = dummyreal |
| 155 |
timeset = .true. |
| 156 |
print*,'setting time = ',dummyreal,' from header line ',i |
| 157 |
endif |
| 158 |
enddo |
| 159 |
endif |
| 160 |
! |
| 161 |
!--now read the timestep data in the dumpfile |
| 162 |
! |
| 163 |
dat(:,:,j) = 0. |
| 164 |
! time(j) = -1.0 ! time not read |
| 165 |
|
| 166 |
! |
| 167 |
!--now read the timestep data in the dumpfile |
| 168 |
! |
| 169 |
i = 0 |
| 170 |
ierr = 0 |
| 171 |
nerr = 0 |
| 172 |
overparts: do while (ierr >= 0) |
| 173 |
i = i + 1 |
| 174 |
if (i > npart_max) then ! reallocate memory if necessary |
| 175 |
npart_max = 10*npart_max |
| 176 |
call alloc(npart_max,nstep_max,ncol+ncalc) |
| 177 |
endif |
| 178 |
read(iunit,*,iostat=ierr) (dat(i,icol,j),icol = 1,10),lab,(dat(i,icol,j),icol=11,ncol) |
| 179 |
if (ierr > 0) then |
| 180 |
nerr = nerr + 1 |
| 181 |
if (nerr <= 10) print "(a,i8,a)",' ERROR reading data from line ',i+nheaderlines,', skipping' |
| 182 |
i = i - 1 ! ignore lines with errors |
| 183 |
endif |
| 184 |
enddo overparts |
| 185 |
close(iunit) |
| 186 |
|
| 187 |
nprint = i - 1 |
| 188 |
nstepsread = nstepsread + 1 |
| 189 |
|
| 190 |
if (nerr > 10) then |
| 191 |
print "(a,i8,a)",' *** WARNING: errors whilst reading file on ',nerr,' lines: skipped these ***' |
| 192 |
endif |
| 193 |
if (ierr < 0) then |
| 194 |
print*,'end of file: npart = ',nprint |
| 195 |
endif |
| 196 |
|
| 197 |
|
| 198 |
npartoftype(:,j) = 0 |
| 199 |
npartoftype(1,j) = nprint |
| 200 |
|
| 201 |
! |
| 202 |
!--now open the sink particle file and read it |
| 203 |
! |
| 204 |
!--find the last underscore in the file name |
| 205 |
ilen = index(rootname,'_',back=.true.) |
| 206 |
if (ilen <= 0) ilen = len_trim(rootname) + 1 |
| 207 |
dumpfile = rootname(1:ilen-1)//'_S' |
| 208 |
inquire(file=trim(dumpfile),exist=iexist) |
| 209 |
if (iexist) then |
| 210 |
open(unit=iunit+1,file=trim(dumpfile),form='formatted',status='old',iostat=ierr) |
| 211 |
if (ierr /= 0) then |
| 212 |
print "(a)",' ERROR: could not open sink particle file '//trim(dumpfile) |
| 213 |
else |
| 214 |
i = npartoftype(1,j) |
| 215 |
ierr = 0 |
| 216 |
nerr = 0 |
| 217 |
oversinks: do while (ierr >= 0) |
| 218 |
i = i + 1 |
| 219 |
if (i > npart_max) then ! reallocate memory if necessary |
| 220 |
npart_max = npart_max + 1000 |
| 221 |
call alloc(npart_max,nstep_max,ncol+ncalc) |
| 222 |
endif |
| 223 |
read(iunit+1,*,iostat=ierr) (dat(i,icol,j),icol = 1,10) |
| 224 |
if (ierr > 0) then |
| 225 |
nerr = nerr + 1 |
| 226 |
if (nerr <= 10) print "(a,i8,a)",' ERROR reading sink data from line ',i+nheaderlines,', skipping' |
| 227 |
i = i - 1 ! ignore lines with errors |
| 228 |
endif |
| 229 |
enddo oversinks |
| 230 |
endif |
| 231 |
npartoftype(2,j) = i - 1 - npartoftype(1,j) |
| 232 |
print "(a,i8,a)",' read ',npartoftype(2,j),' sink particles from '//trim(dumpfile) |
| 233 |
close(iunit+1) |
| 234 |
else |
| 235 |
print "(a)",' sink particle file ('//trim(dumpfile)//') not present' |
| 236 |
endif |
| 237 |
! |
| 238 |
!--look for a _t file for the time (interim measure) |
| 239 |
! |
| 240 |
dumpfile = rootname(1:ilen-1)//'_t' |
| 241 |
inquire(file=trim(dumpfile),exist=iexist) |
| 242 |
if (iexist) then |
| 243 |
open(unit=iunit+2,file=trim(dumpfile),form='formatted',status='old',iostat=ierr) |
| 244 |
if (ierr /= 0) then |
| 245 |
print "(a)",' ERROR: could not open time file '//trim(dumpfile) |
| 246 |
else |
| 247 |
read(iunit+2,*,iostat=ierr) time(j) |
| 248 |
if (ierr /= 0) then |
| 249 |
print "(a)",' ERROR reading time from file '//trim(dumpfile) |
| 250 |
else |
| 251 |
print*,' got time = ',time(j),' from file '//trim(dumpfile) |
| 252 |
endif |
| 253 |
endif |
| 254 |
close(iunit+2) |
| 255 |
endif |
| 256 |
|
| 257 |
return |
| 258 |
|
| 259 |
end subroutine read_data_urban |
| 260 |
|
| 261 |
!!------------------------------------------------------------ |
| 262 |
!! set labels for each column of data |
| 263 |
!!------------------------------------------------------------ |
| 264 |
|
| 265 |
subroutine set_labels_urban |
| 266 |
use labels, only:label,labelvec,labeltype,iamvec,& |
| 267 |
ix,ivx,ih,irho,iutherm,ipmass,make_vector_label |
| 268 |
use settings_data, only:ndim,ndimV,ntypes,UseTypeInRenderings |
| 269 |
use geometry, only:labelcoord |
| 270 |
!use settings_units, only:units,unitslabel |
| 271 |
integer :: i |
| 272 |
|
| 273 |
if (ndim <= 0 .or. ndim > 3) then |
| 274 |
print*,'*** ERROR: ndim = ',ndim,' in set_labels_urban ***' |
| 275 |
return |
| 276 |
endif |
| 277 |
if (ndimV <= 0 .or. ndimV > 3) then |
| 278 |
print*,'*** ERROR: ndimV = ',ndimV,' in set_labels_urban ***' |
| 279 |
return |
| 280 |
endif |
| 281 |
|
| 282 |
do i=1,ndim |
| 283 |
ix(i) = i |
| 284 |
enddo |
| 285 |
ivx = 4 |
| 286 |
ipmass = 7 |
| 287 |
ih = 8 |
| 288 |
irho = 9 |
| 289 |
iutherm = 10 |
| 290 |
|
| 291 |
label(ix(1:ndim)) = labelcoord(1:ndim,1) |
| 292 |
label(ipmass) = 'particle mass' |
| 293 |
label(ih) = 'h' |
| 294 |
label(irho) = 'density' |
| 295 |
if (iutherm > 0) label(iutherm) = 'u' |
| 296 |
label(11) = 't_{dust}' |
| 297 |
label(12) = 'N_{col}' |
| 298 |
label(13) = 'N_{loc}' |
| 299 |
call make_vector_label('v',ivx,ndimV,iamvec,labelvec,label,labelcoord(:,1)) |
| 300 |
! |
| 301 |
!--set labels for each particle type |
| 302 |
! |
| 303 |
ntypes = 2 |
| 304 |
labeltype(1) = 'gas' |
| 305 |
labeltype(2) = 'sink' |
| 306 |
UseTypeInRenderings(1) = .true. |
| 307 |
UseTypeInRenderings(2) = .false. |
| 308 |
|
| 309 |
!----------------------------------------------------------- |
| 310 |
|
| 311 |
return |
| 312 |
end subroutine set_labels_urban |
| 313 |
end module readdata_urban |