Debian Codegraph @

src/read_data_aly.f90

raw
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-2013 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 ABDEL REHEAM's SPH CODE
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 module readdata_aly
49 use params, only:maxplot
50 implicit none
51 character(len=16), dimension(maxplot) :: compName
52
53 public :: read_data_aly, set_labels_aly
54
55 private
56
57 contains
58
59 subroutine read_data_aly(rootname,indexstart,ipos,nstepsread)
60 use particle_data, only:npartoftype,masstype,time,gamma,dat,maxpart,maxstep,maxcol,iamtype
61 use params
62 use filenames, only:nfiles
63 use settings_data, only:ndim,ndimV,ncolumns,ncalc, &
64 buffer_data,iverbose,debugmode,ntypes
65 use mem_allocation, only:alloc
66 use labels, only:ipr,ivx,ih,irho,labeltype
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,ierr,iunit,j,iblock
72 integer :: npart_max,nstep_max
73
74 integer, dimension(:), allocatable :: itype
75 character(len=7) :: keyword
76 character(len=70) :: title
77 character(len=1) :: dumchar
78 character(len=16) :: unitsys
79 integer :: istep,jtype,np,ione,kk,idum,nblock
80 real(kind=sing_prec) :: version,timesingle,dum
81 real(kind=doub_prec) :: versiond,timedbl
82 real :: timein,dx,dy
83 logical :: singleprecision
84
85 iunit = 11 ! file unit number
86 nstepsread = 0
87 if (rootname(1:1) /= ' ') then
88 datfile = trim(rootname)
89 else
90 print*,' **** no data read **** '
91 return
92 endif
93
94 if (iverbose >= 1) print "(1x,a)",'reading Aly format'
95 write(*,"(23('-'),1x,a,1x,23('-'))") trim(datfile)
96
97 ndim = 2
98 ndimV = 2
99 !
100 !--open data file and read data
101 !
102 open(unit=iunit,iostat=ierr,file=datfile,status='old',form='unformatted',access='stream')
103 if (ierr /= 0) then
104 print*,' *** Error opening '//trim(datfile)//' ***'
105 return
106 endif
107 !
108 !--read first header line
109 !
110 read(iunit,iostat=ierr,end=80) keyword
111 read(iunit,iostat=ierr,end=80) version
112 read(iunit,iostat=ierr,end=80) title
113 read(iunit,iostat=ierr,end=80) istep
114 read(iunit,iostat=ierr,end=80) timesingle
115 timein = timesingle
116 read(iunit,iostat=ierr,end=80) np
117 read(iunit,iostat=ierr,end=80) ione
118 if (ierr /= 0 .or. np <= 0 .or. timesingle < 0.) then
119 !
120 !--try single precision
121 !
122 rewind(iunit)
123 read(iunit,iostat=ierr,end=80) keyword
124 read(iunit,iostat=ierr,end=80) versiond
125 version = real(versiond,kind=kind(version))
126 read(iunit,iostat=ierr,end=80) title
127 read(iunit,iostat=ierr,end=80) istep
128 read(iunit,iostat=ierr,end=80) timedbl
129 timein = real(timedbl)
130 read(iunit,iostat=ierr,end=80) np
131 read(iunit,iostat=ierr,end=80) ione
132 singleprecision = .false.
133 if (ierr /= 0 .or. np < 0 .or. timedbl < 0.) then
134 print "(a)",' *** Error reading first header ***'
135 close(iunit)
136 return
137 endif
138 endif
139 print "(a,f4.2)",' keyword = '//trim(keyword)//' version = ',version
140 !print "(a)",' title = '//trim(title)
141 print "(a,i6,a,es10.3,a,i6)",' step = ',istep,' time = ',timein,' np = ',np
142 !
143 !--allocate memory for data arrays
144 !
145 if (buffer_data) then
146 nstep_max = max(nfiles,maxstep,indexstart)
147 else
148 nstep_max = max(1,maxstep,indexstart)
149 endif
150 npart_max = max(int(1.1*np),maxpart)
151 ncolumns = 7
152 if (.not.allocated(dat) .or. npart_max > maxpart &
153 .or. nstep_max > maxstep .or. ncolumns+ncalc > maxcol) then
154 call alloc(npart_max,nstep_max,ncolumns+ncalc,mixedtypes=.true.)
155 endif
156
157 i = indexstart
158 nstepsread = 0
159 time(i) = timein
160 gamma(i) = 5./3.
161 npartoftype(1,i) = np
162
163 do j=1,np
164 read(iunit,iostat=ierr,end=67) idum,(dat(j,kk,i),kk=1,2),dum
165 enddo
166 read(iunit,iostat=ierr,end=67) nblock
167 read(iunit,iostat=ierr,end=67) (idum,j=1,nblock)
168
169 ntypes = 4
170 allocate(itype(np))
171 read(iunit,iostat=ierr,end=67) (itype(j),j=1,nblock)
172 npartoftype(:,i) = 0
173 do j=1,np
174 jtype = itype(j)
175 !--map types from code types to splash types
176 select case(jtype)
177 case(1)
178 jtype = 2 ! boundary
179 case(2)
180 jtype = 1 ! water
181 case default ! unknown
182 jtype = 4
183 end select
184 iamtype(j,i) = int(jtype,kind=kind(iamtype))
185 npartoftype(jtype,i) = npartoftype(jtype,i) + 1
186 enddo
187 deallocate(itype)
188 read(iunit,iostat=ierr,end=67) (dumchar,j=1,nblock)
189 read(iunit,iostat=ierr,end=67) (idum,j=1,nblock)
190
191 call set_labels_aly
192 do iblock=1,1
193
194 read(iunit,iostat=ierr,end=67) nblock
195 read(iunit,iostat=ierr,end=67) idum
196
197 do j=1,nblock
198 read(iunit,iostat=ierr,end=67) compName(j),unitsys,idum,idum,dum
199 !print*,trim(compName(j))
200 enddo
201
202 do j=1,np
203 read(iunit,iostat=ierr,end=67) dum,dat(j,ipr,i),dat(j,ivx,i),dat(j,ivx+1,i),dat(j,1,i),dat(j,2,i)
204 if (abs(dum) < tiny(0.)) then
205 npartoftype(iamtype(j,i),i) = npartoftype(iamtype(j,i),i) - 1 ! remove from previous type
206 iamtype(j,i) = 3
207 npartoftype(3,i) = npartoftype(3,i) + 1 ! add to "box" type
208 endif
209 enddo
210 enddo
211 !
212 !--fake other properties: density, mass, smoothing length etc.
213 !
214 masstype(1,i) = 1./npartoftype(1,i)
215 !
216 !--assume smoothing length to be the max dimension divided by the number of particles^(1/ndim)
217 !
218 dx = maxval(dat(1:np,1,i)) - minval(dat(1:np,1,i))
219 dy = maxval(dat(1:np,2,i)) - minval(dat(1:np,2,i))
220 dat(:,ih,i) = dx/(npartoftype(1,i))**(1./ndim)*(dy/dx)
221 print*,' WARNING: ASSUMING SMOOTHING LENGTH = ',dat(1,ih,i),' AND ARBITRARY PARTICLE MASSES'
222 dat(:,irho,i) = 1.
223 nstepsread = 1
224 do jtype=1,ntypes
225 write(*,"(' n(',a,') = ',i6)",advance="no") trim(labeltype(jtype)),npartoftype(jtype,i)
226 enddo
227 write(*,*)
228 !read*
229
230
231 goto 68
232 67 continue
233 print "(a)",' > end of file reached <'
234 68 continue
235 !
236 !--close data file and return
237 !
238 close(unit=11)
239
240 if (debugmode) print*,'DEBUG> Read steps ',indexstart,'->',indexstart + nstepsread - 1, &
241 ' last step ntot = ',sum(npartoftype(:,indexstart+nstepsread-1))
242 return
243
244 80 continue
245 print*,' *** data file empty : no timesteps ***'
246 return
247
248 end subroutine read_data_aly
249
250 !!------------------------------------------------------------
251 !! set labels for each column of data
252 !!------------------------------------------------------------
253
254 subroutine set_labels_aly
255 use labels, only:ix,ivx,ih,irho,ipr,&
256 iamvec,labelvec,label,labeltype
257 use params
258 use settings_data, only:ndim,ndimV,UseTypeInRenderings
259 use geometry, only:labelcoord
260 integer :: i
261
262 if (ndim <= 0 .or. ndim > 3) then
263 print*,'*** ERROR: ndim = ',ndim,' in set_labels_aly ***'
264 return
265 endif
266 if (ndimV <= 0 .or. ndimV > 3) then
267 print*,'*** ERROR: ndimV = ',ndimV,' in set_labels_aly ***'
268 return
269 endif
270
271 do i=1,ndim
272 ix(i) = i
273 enddo
274 ivx = ndim + 1
275 ipr = ndim + ndimV + 1
276 irho = ipr + 1
277 ih = irho + 1
278 label(ipr) = 'pressure'
279 label(irho) = 'density'
280 label(ih) = 'h'
281
282 label(ix(1:ndim)) = labelcoord(1:ndim,1)
283 !
284 !--label vector quantities (e.g. velocity) appropriately
285 !
286 iamvec(ivx:ivx+ndimV-1) = ivx
287 labelvec(ivx:ivx+ndimV-1) = 'v'
288
289 !
290 !--set labels for each type of particles
291 !
292 labeltype(1) = 'water'
293 labeltype(2) = 'boundary'
294 labeltype(3) = 'box'
295 labeltype(4) = 'unknown'
296 UseTypeInRenderings(1) = .true.
297 UseTypeInRenderings(2) = .false.
298 UseTypeInRenderings(3) = .false.
299 UseTypeInRenderings(4) = .false.
300
301 !-----------------------------------------------------------
302
303 end subroutine set_labels_aly
304
305 end module readdata_aly