Debian Codegraph @

src/read_data_vanaverbeke.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 ! THIS VERSION IS FOR READING UNFORMATTED OUTPUT
28 ! FROM SIGFRIED VANAVERBEKE'S CODE
29 ! (ie. STRAIGHT FROM THE DATA DUMP)
30 !
31 ! SOME CHOICES FOR THIS FORMAT CAN BE SET USING THE FOLLOWING
32 ! ENVIRONMENT VARIABLES:
33 !
34 ! VSPLASH_SINGLEPREC if 'YES' or 'TRUE' then assumes data is single precision
35 ! VSPLASH_NCOL to change the number of columns read from the file,
36 ! e.g. setenv VSPLASH_NCOL=13
37 !
38 ! the data is stored in the global array dat
39 !
40 ! >> this subroutine must return values for the following: <<
41 !
42 ! ncolumns : number of data columns
43 ! ndim, ndimV : number of spatial, velocity dimensions
44 ! nstepsread : number of steps read from this file
45 !
46 ! maxplot,maxpart,maxstep : dimensions of main data array
47 ! dat(maxplot,maxpart,maxstep) : main data array
48 !
49 ! npartoftype(1:6,maxstep) : number of particles of each type in each timestep
50 !
51 ! time(maxstep) : time at each step
52 ! gamma(maxstep) : gamma at each step
53 !
54 ! most of these values are stored in global arrays
55 ! in the module 'particle_data'
56 !-------------------------------------------------------------------------
57
58 module readdata_vanaverbeke
59 implicit none
60
61 public :: read_data_vanaverbeke, set_labels_vanaverbeke
62
63 private
64 contains
65
66 subroutine read_data_vanaverbeke(rootname,indexstart,ipos,nstepsread)
67 use particle_data, only:dat,time,npartoftype,gamma,maxpart
68 use params
69 use settings_data, only:ndim,ndimV,ncolumns
70 use mem_allocation, only:alloc
71 use system_utils, only:lenvironment,ienvironment
72 integer, intent(in) :: indexstart,ipos
73 integer, intent(out) :: nstepsread
74 character(len=*), intent(in) :: rootname
75 integer :: i,j,k,ierr
76 integer :: nprint,ntotal,npart_max,nstep_max
77 integer :: ncol,nread,nerr,ncoltemp,nsink,nsinkcol,nacc
78 logical :: iexist,doubleprec
79 integer, parameter :: iunit = 15
80 character(len=len(rootname)) :: dumpfile
81 real :: timei,gammai
82 real(doub_prec), dimension(maxplot) :: datdb
83 real(doub_prec) :: timedb,gammadb
84
85 nstepsread = 0
86 nstep_max = 0
87 npart_max = maxpart
88 dumpfile = trim(rootname)
89 !
90 !--check if first data file exists
91 !
92 inquire(file=dumpfile,exist=iexist)
93 if (.not.iexist) then
94 print "(a)",' *** error: '//trim(dumpfile)//': file not found ***'
95 return
96 endif
97 !
98 !--fix number of spatial dimensions
99 !
100 ndim = 3
101 ndimV = 3
102
103 !--number of columns to read from file
104 ncol = 10
105 nsinkcol = 7
106 doubleprec = .true.
107
108 !--can override these settings with environment variables
109 if (lenvironment('VSPLASH_SINGLEPREC')) doubleprec = .false.
110 ncoltemp = ienvironment('VSPLASH_NCOL')
111 if (ncoltemp > 0) ncol = ncoltemp
112 !
113 !--allocate memory initially
114 !
115 nstep_max = max(nstep_max,indexstart,1)
116 j = indexstart
117 nstepsread = 0
118 print "(a)",' reading Vanaverbeke format...'
119
120 write(*,"(26('>'),1x,a,1x,26('<'))") trim(dumpfile)
121 !
122 !--open the (unformatted) binary file and read the number of particles
123 !
124 open(unit=iunit,file=dumpfile,status='old',form='unformatted',iostat=ierr)
125 if (ierr /= 0) then
126 print "(a)",'*** ERROR OPENING '//trim(dumpfile)//' ***'
127 return
128 else
129 timei = 0.
130 read(iunit,iostat=ierr) nprint,nacc,nsink
131 print "(3(a,i10))",'npart:',nprint,' naccreted:',nacc,' nsinks:',nsink
132 if (doubleprec) then
133 read(iunit,iostat=ierr) timedb,gammadb
134 timei = real(timedb)
135 gammai = real(gammadb)
136 else
137 read(iunit,iostat=ierr) timei,gammai
138 endif
139 print "(2(a,1pe12.3))",'time:',timei,' gamma:',gammai
140
141 !--barf if stupid values read
142 if (nprint < 0 .or. nacc < 0 .or. nsink < 0 .or. nsink > 1e7) then
143 print "(a)",' *** ERROR IN TIMESTEP HEADER: WRONG ENDIAN? (or old header format)?'
144 close(iunit)
145 return
146 elseif (ierr /= 0) then
147 print "(a)",'*** ERROR READING TIMESTEP HEADER: WRONG ENDIAN? ***'
148 close(iunit)
149 return
150 endif
151 if (timei < 0. .or. gammai < 1.0 .or. gammai > 2.0) then
152 print*,'*** ERROR IN HEADER: strange time and/or gamma read: wrong precision?'
153 endif
154 ncolumns = ncol
155
156 ntotal = nprint + nsink
157 if (.not.allocated(dat) .or. ntotal > npart_max) then
158 npart_max = max(npart_max,ntotal)
159 call alloc(npart_max,nstep_max,ncolumns)
160 endif
161 !
162 !--now read the timestep data in the dumpfile
163 !
164 dat(:,:,j) = 0.
165 time(j) = timei
166 gamma(j) = gammai
167
168 if (doubleprec) then
169 nerr = 0
170 nread = 0
171 do i=1,nprint
172 nread = nread + 1
173 read(iunit,end=44,iostat=ierr) (datdb(k),k=1,ncol)
174 if (ierr /= 0) then
175 nerr = nerr + 1
176 else
177 dat(i,1:ncol,j) = real(datdb(1:ncol))
178 endif
179 enddo
180 do i=nprint+1,nprint+nsink
181 nread = nread + 1
182 read(iunit,end=44,iostat=ierr) (datdb(k),k=1,nsinkcol)
183 if (ierr /= 0) then
184 nerr = nerr + 1
185 else
186 dat(i,1:nsinkcol,j) = real(datdb(1:nsinkcol))
187 endif
188 enddo
189 else
190 nerr = 0
191 nread = 0
192 do i=1,nprint
193 nread = nread + 1
194 read(iunit,end=44,iostat=ierr) dat(i,1:ncol,j)
195 if (ierr /= 0) nerr = nerr + 1
196 enddo
197 do i=nprint+1,nprint+nsink
198 nread = nread + 1
199 read(iunit,end=44,iostat=ierr) dat(i,1:nsinkcol,j)
200 if (ierr /= 0) nerr = nerr + 1
201 enddo
202 endif
203
204 goto 45
205 44 continue
206 print "(a,i10)",' WARNING: END-OF-FILE AT LINE ',nread
207 45 continue
208 if (nerr > 0) print *,'*** WARNING: ERRORS DURING READ ON ',nerr,' LINES'
209
210 nstepsread = nstepsread + 1
211 npartoftype(1,j) = nprint - nacc
212 npartoftype(2,j) = nacc
213 npartoftype(3,j) = nsink
214 j = j + 1
215
216 endif
217
218 close(iunit)
219
220 if (allocated(npartoftype)) then
221 print*,'>> end of dump file: nsteps =',j-1,'ntot = ',sum(npartoftype(:,j-1))
222 endif
223 return
224
225 end subroutine read_data_vanaverbeke
226
227 !!------------------------------------------------------------
228 !! set labels for each column of data
229 !!------------------------------------------------------------
230
231 subroutine set_labels_vanaverbeke
232 use labels, only:label,labelvec,labeltype,iamvec,&
233 ix,ivx,ih,irho,iutherm,ipmass,ispsound
234 use settings_data, only:ndim,ndimV,ntypes,UseTypeInRenderings
235 use geometry, only:labelcoord
236 !use settings_units, only:units,unitslabel
237 integer :: i
238
239 if (ndim <= 0 .or. ndim > 3) then
240 print*,'*** ERROR: ndim = ',ndim,' in set_labels_vanaverbeke ***'
241 return
242 endif
243 if (ndimV <= 0 .or. ndimV > 3) then
244 print*,'*** ERROR: ndimV = ',ndimV,' in set_labels_vanaverbeke ***'
245 return
246 endif
247
248 do i=1,ndim
249 ix(i) = i
250 enddo
251 ivx = 4
252 ipmass = 7
253 ih = ipmass + 1
254 iutherm = ih + 1
255 irho = iutherm + 1
256 ispsound = 0
257
258 label(ix(1:ndim)) = labelcoord(1:ndim,1)
259 label(ih) = 'h'
260 if (irho > 0) label(irho) = '\gr'
261 if (ipmass > 0) label(ipmass) = 'particle mass'
262 if (iutherm > 0) label(iutherm) = 'u'
263 if (ispsound > 0) label(ispsound) = 'c_s'
264
265 if (ivx /= 0) then
266 iamvec(ivx:ivx+ndimV-1) = ivx
267 labelvec(ivx:ivx+ndimV-1) = 'v'
268 do i=1,ndimV
269 label(ivx+i-1) = trim(labelvec(ivx))//'\d'//trim(labelcoord(i,1))
270 enddo
271 endif
272 !
273 !--set labels for each particle type
274 !
275 ntypes = 3
276 labeltype(1) = 'gas'
277 labeltype(2) = 'accreted/dead'
278 labeltype(3) = 'sink'
279 UseTypeInRenderings(1) = .true.
280 UseTypeInRenderings(2) = .true.
281 UseTypeInRenderings(3) = .false.
282
283 !-----------------------------------------------------------
284
285 return
286 end subroutine set_labels_vanaverbeke
287 end module readdata_vanaverbeke