Debian Codegraph @

src/read_data_bauswein.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-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 ! THIS VERSION IS FOR READING UNFORMATTED OUTPUT FROM ANDREAS BAUSWEIN'S CODE
28 ! (ie. STRAIGHT FROM THE DATA DUMP)
29 !
30 ! *** CONVERTS TO SINGLE PRECISION ***
31 !
32 ! SOME CHOICES FOR THIS FORMAT CAN BE SET USING THE FOLLOWING
33 ! ENVIRONMENT VARIABLES:
34 !
35 ! BSPLASH_R8 if 'YES' or 'TRUE' then assumes data is double precision
36 ! BSPLASH_NCOL to change the number of columns read from the file,
37 ! e.g. setenv BSPLASH_NCOL=22
38 !
39 ! the data is stored in the global array dat
40 !
41 ! >> this subroutine must return values for the following: <<
42 !
43 ! ncolumns : number of data columns
44 ! ndim, ndimV : number of spatial, velocity dimensions
45 ! nstepsread : number of steps read from this file
46 !
47 ! maxplot,maxpart,maxstep : dimensions of main data array
48 ! dat(maxplot,maxpart,maxstep) : main data array
49 !
50 ! npartoftype(1:6,maxstep) : number of particles of each type in each timestep
51 !
52 ! time(maxstep) : time at each step
53 ! gamma(maxstep) : gamma at each step
54 !
55 ! most of these values are stored in global arrays
56 ! in the module 'particle_data'
57 !-------------------------------------------------------------------------
58
59 module readdata_bauswein
60 implicit none
61
62 public :: read_data_bauswein, set_labels_bauswein
63
64 private
65 contains
66
67 subroutine read_data_bauswein(rootname,indexstart,ipos,nstepsread)
68 use particle_data, only:dat,time,npartoftype,gamma,maxpart,maxcol
69 use params
70 use settings_data, only:ndim,ndimV,ncolumns
71 use mem_allocation, only:alloc
72 use system_utils, only:lenvironment,ienvironment
73 integer, intent(in) :: indexstart,ipos
74 integer, intent(out) :: nstepsread
75 character(len=*), intent(in) :: rootname
76 integer :: i,j,k,ierr
77 integer :: nprint,n1,npart_max,nstep_max
78 integer :: ncol,nread,nerr,ncoltemp
79 logical :: iexist,doubleprec
80 character(len=len(rootname)) :: dumpfile
81 real :: timei,dti
82 real(doub_prec), dimension(maxcol) :: datdb
83 real(doub_prec) :: timedb,dtdb
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 = 21
105 doubleprec = .false.
106
107 !--can override these settings with environment variables
108 if (lenvironment('BSPLASH_R8')) doubleprec = .true.
109 ncoltemp = ienvironment('BSPLASH_NCOL')
110 if (ncoltemp > 0) ncol = ncoltemp
111 !
112 !--allocate memory initially
113 !
114 nstep_max = max(nstep_max,indexstart,1)
115 j = indexstart
116 nstepsread = 0
117
118 print "(1x,a)",'reading Andreas Bauswein format'
119 write(*,"(26('>'),1x,a,1x,26('<'))") trim(dumpfile)
120 !
121 !--open the (unformatted) binary file and read the number of particles
122 !
123 open(unit=15,file=dumpfile,status='old',form='unformatted',iostat=ierr)
124 if (ierr /= 0) then
125 print "(a)",'*** ERROR OPENING '//trim(dumpfile)//' ***'
126 return
127 else
128 !
129 !--read the number of particles in the header and allocate memory
130 !
131 if (doubleprec) then
132 read(15,end=55,iostat=ierr) nprint,n1,timedb,dtdb
133 timei = real(timedb)
134 dti = real(dtdb)
135 else
136 read(15,end=55,iostat=ierr) nprint,n1,timei,dti
137 endif
138 print "(a,f10.2,a,i10,a,i10,a,f10.4)",' time: ',timei,' npart: ',nprint,' n1: ',n1,' dt = ',dti
139 !--barf if stupid values read
140 if (nprint <= 0 .or. nprint > 1e10) then
141 print "(a)",' *** ERRORS IN TIMESTEP HEADER: WRONG ENDIAN? ***'
142 close(15)
143 return
144 elseif (ierr /= 0) then
145 print "(a)",'*** WARNING: ERRORS READING HEADER ***'
146 endif
147 if (timei < 0. .or. dti < 0.) print "(a)",'*** ERROR: t < 0: use setenv BSPLASH_R8=TRUE for double precision'
148 ncolumns = ncol
149
150 if (.not.allocated(dat) .or. nprint > npart_max) then
151 npart_max = max(npart_max,nprint)
152 call alloc(npart_max,nstep_max,ncolumns)
153 endif
154 !
155 !--now read the timestep data in the dumpfile
156 !
157 dat(:,:,j) = 0.
158 time(j) = timei
159
160 if (doubleprec) then
161 nread = 0
162 nerr = 0
163 do i=1,nprint
164 nread = nread + 1
165 read(15,end=44,iostat=ierr) (datdb(k),k=1,ncol)
166 if (ierr /= 0) nerr = nerr + 1
167 dat(i,4,j) = real(datdb(1))
168 dat(i,1:3,j) = real(datdb(2:4))
169 dat(i,5:ncol,j) = real(datdb(5:ncol))
170 enddo
171 else
172 nread = 0
173 nerr = 0
174 do i=1,nprint
175 nread = nread + 1
176 read(15,end=44,iostat=ierr) dat(i,4,j),dat(i,1:3,j),(dat(i,k,j),k=5,ncol)
177 if (ierr /= 0) nerr = nerr + 1
178 enddo
179 endif
180
181 44 continue
182 if (nerr > 0) print *,'*** WARNING: ERRORS DURING READ ON ',nerr,' LINES'
183
184 if (nread < nprint) then
185 print "(a)",' WARNING: END OF FILE: read to particle ',nread
186 nprint = nread
187 endif
188
189 nstepsread = nstepsread + 1
190 npartoftype(1,j) = nprint
191 gamma(j) = 1.666666666667
192 j = j + 1
193
194 endif
195
196 55 continue
197 !
198 !--reached end of file during header read
199 !
200 close(15)
201
202 if (allocated(npartoftype)) then
203 print*,'>> end of dump file: nsteps =',j-1,'ntot = ',sum(npartoftype(:,j-1))
204 endif
205 return
206
207 end subroutine read_data_bauswein
208
209 !!------------------------------------------------------------
210 !! set labels for each column of data
211 !!------------------------------------------------------------
212
213 subroutine set_labels_bauswein
214 use labels, only:label,labelvec,labeltype,iamvec,&
215 ix,ivx,ih,irho,iutherm,ipmass,make_vector_label
216 use settings_data, only:ndim,ndimV,ntypes,UseTypeInRenderings
217 use geometry, only:labelcoord
218 !use settings_units, only:units,unitslabel
219 integer :: i,ipmom
220
221 if (ndim <= 0 .or. ndim > 3) then
222 print*,'*** ERROR: ndim = ',ndim,' in set_labels_bauswein ***'
223 return
224 endif
225 if (ndimV <= 0 .or. ndimV > 3) then
226 print*,'*** ERROR: ndimV = ',ndimV,' in set_labels_bauswein ***'
227 return
228 endif
229
230 do i=1,ndim
231 ix(i) = i
232 enddo
233 ih = 4
234 ivx = 5
235 ipmom = 8
236 iutherm = 11
237 ipmass = 14
238 irho = 17
239
240 label(ix(1:ndim)) = labelcoord(1:ndim,1)
241 label(ih) = 'h'
242 if (iutherm > 0) label(iutherm) = 'u'
243 label(12) = 'psi_{pot}'
244 label(13) = 'alpha_{pot}'
245 label(ipmass) = 'particle mass'
246 label(15) = '\gr'
247 label(16) = 'P\deff'
248 label(irho) = '\gr*'
249 label(18) = 'tau'
250 label(19) = '\ga_{visc}'
251 label(20) = 'Ye'
252 label(21) = 'temperature'
253
254 call make_vector_label('v',ivx,ndimV,iamvec,labelvec,label,labelcoord(:,1))
255 call make_vector_label('momentum',ipmom,ndimV,iamvec,labelvec,label,labelcoord(:,1))
256 !
257 !--set labels for each particle type
258 !
259 ntypes = 1
260 labeltype(1) = 'gas'
261 UseTypeInRenderings(1) = .true.
262
263 !-----------------------------------------------------------
264
265 return
266 end subroutine set_labels_bauswein
267 end module readdata_bauswein