Debian Codegraph @

src/read_data_spyros.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-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 THE VINE CODE
28 ! (ie. STRAIGHT FROM THE DATA DUMP)
29 !
30 ! *** CONVERTS TO SINGLE PRECISION ***
31 !
32 ! the data is stored in the global array dat
33 !
34 ! >> this subroutine must return values for the following: <<
35 !
36 ! ncolumns : number of data columns
37 ! ndim, ndimV : number of spatial, velocity dimensions
38 ! nstepsread : number of steps read from this file
39 !
40 ! maxplot,maxpart,maxstep : dimensions of main data array
41 ! dat(maxplot,maxpart,maxstep) : main data array
42 !
43 ! npartoftype(1:6,maxstep) : number of particles of each type in each timestep
44 !
45 ! time(maxstep) : time at each step
46 ! gamma(maxstep) : gamma at each step
47 !
48 ! most of these values are stored in global arrays
49 ! in the module 'particle_data'
50 !-------------------------------------------------------------------------
51
52 module readdata_spyros
53 implicit none
54
55 public :: read_data_spyros, set_labels_spyros
56
57 private
58 contains
59
60 subroutine read_data_spyros(rootname,indexstart,ipos,nstepsread)
61 use particle_data
62 use params
63 use settings_data, only:ndim,ndimV,ncolumns,ncalc
64 use mem_allocation
65 integer, intent(in) :: indexstart,ipos
66 integer, intent(out) :: nstepsread
67 character(len=*), intent(in) :: rootname
68
69 integer :: j,ierr,ntoti,irec
70 integer :: npart_max,nstep_max,ncolstep
71 logical :: iexist
72
73 character(len=len(rootname)+10) :: dumpfile
74
75 !--we are assuming dump is double precision
76 real(doub_prec) :: variable1,variable2
77 real(doub_prec), dimension(:), allocatable :: dattemp
78
79 nstepsread = 0
80 npart_max = maxpart
81
82 dumpfile = trim(rootname)
83 !
84 !--check if first data file exists
85 !
86 inquire(file=dumpfile,exist=iexist)
87 if (.not.iexist) then
88 print "(a)",' *** error: '//trim(dumpfile)//': file not found ***'
89 return
90 endif
91 !
92 !--fix number of spatial dimensions
93 !
94 ndim = 3
95 ndimV = 3
96 !
97 !--allocate memory initially
98 !
99 nstep_max = max(indexstart,1)
100
101 j = indexstart
102 nstepsread = 0
103
104 print "(1x,a)",'reading Spyros Kitsonias'' format'
105 write(*,"(26('>'),1x,a,1x,26('<'))") trim(dumpfile)
106 !
107 !--open the (unformatted) binary file and read the number of particles
108 !
109 open(unit=15,iostat=ierr,file=dumpfile,status='old',form='unformatted',&
110 access='direct',recl=4000000)
111 if (ierr /= 0) then
112 print "(a)",'*** ERROR OPENING '//trim(dumpfile)//' ***'
113 else
114 !
115 !--read timestep header (integers only)
116 !
117 read(15,iostat=ierr) variable1,variable2
118 if (ierr < 0) then
119 print "(a)",'*** END OF FILE IN TIMESTEP HEADER ***'
120 return
121 elseif (ierr /= 0) then
122 print "(a)",'*** ERROR READING TIMESTEP HEADER ***'
123 return
124 endif
125 !
126 !--get number of particles from header and allocate memory
127 !
128 ntoti = int(variable1)
129 ncolstep = int(variable2)
130 ncolumns = ncolstep
131
132 if (.not.allocated(dat) .or. ntoti > npart_max) then
133 npart_max = max(npart_max,INT(1.1*ntoti))
134 call alloc(npart_max,nstep_max,ncolstep+ncalc)
135 endif
136 !
137 !--rewind file
138 !
139 rewind(15)
140 endif
141
142 npart_max = max(npart_max,ntoti)
143 !
144 !--allocate/reallocate memory if j > maxstep
145 !
146 if (j > maxstep) then
147 call alloc(maxpart,j+2*nstepsread,maxcol)
148 endif
149 !
150 !--allocate a temporary array for double precision variables
151 !
152 if (allocated(dattemp)) deallocate(dattemp)
153 allocate(dattemp(npart_max),stat=ierr)
154 dattemp = 0.
155 if (ierr /= 0) print*,'not enough memory in read_data_spyros'
156 !
157 !--now read the timestep data in the dumpfile
158 !
159 print "(a,i5,a,f8.3,a,i8)",'| step ',j,': t = ',time(j),' ntotal = ',ntoti
160
161 nstepsread = nstepsread + 1
162 !
163 !--set particle numbers
164 !
165 npartoftype(:,j) = 0
166 npartoftype(1,j) = ntoti
167 !
168 !--read all records
169 !
170 overcolumns: do irec=1,ncolstep
171 read(15,rec=irec,iostat=ierr) variable1,variable2,dattemp(1:ntoti)
172 if (ierr < 0) then
173 print "(a)",'*** END OF FILE IN READ DATA (CHECK PRECISION) ***'
174 exit overcolumns
175 elseif (ierr /= 0) then
176 print "(a)",'*** ERROR READING DATA ***'
177 exit overcolumns
178 endif
179 !
180 !--time and gamma
181 !
182 if (irec==2) time(j) = real(variable1)
183 if (irec==5) gamma(j) = real(variable2)
184 !
185 !--convert to single precision
186 !
187 dat(1:ntoti,irec,j) = real(dattemp(1:ntoti))
188
189 enddo overcolumns
190 !
191 !--clean up
192 !
193 if (allocated(dattemp)) deallocate(dattemp)
194 !
195 !--close file
196 !
197 close(15)
198 if (nstepsread > 0) then
199 print*,'>> end of dump file: ntotal = ',sum(npartoftype(:,j))
200 endif
201
202
203 return
204
205 end subroutine read_data_spyros
206
207 !!------------------------------------------------------------
208 !! set labels for each column of data
209 !!------------------------------------------------------------
210
211 subroutine set_labels_spyros
212 use labels
213 use params
214 use settings_data
215 use geometry, only:labelcoord
216 integer :: i
217
218 if (ndim <= 0 .or. ndim > 3) then
219 print*,'*** ERROR: ndim = ',ndim,' in set_labels_spyros ***'
220 return
221 endif
222 if (ndimV <= 0 .or. ndimV > 3) then
223 print*,'*** ERROR: ndimV = ',ndimV,' in set_labels_spyros ***'
224 return
225 endif
226
227 do i=1,ndim
228 ix(i) = i
229 enddo
230 ivx = 4
231 ih = 10 ! smoothing length
232 iutherm = 9 ! thermal energy
233 ipmass = 8 ! particle mass
234 irho = 7 ! location of rho in data array
235
236 label(ix(1:ndim)) = labelcoord(1:ndim,1)
237 label(irho) = 'density'
238 label(iutherm) = 'temperature'
239 label(ih) = 'h'
240 label(ipmass) = 'particle mass'
241 !
242 !--set labels for vector quantities
243 !
244 iamvec(ivx:ivx+ndimV-1) = ivx
245 labelvec(ivx:ivx+ndimV-1) = 'v'
246 do i=1,ndimV
247 label(ivx+i-1) = trim(labelvec(ivx))//'\d'//labelcoord(i,1)
248 enddo
249 !
250 !--set labels for each particle type
251 !
252 ntypes = 1
253 labeltype(1) = 'gas'
254 UseTypeInRenderings(1) = .true.
255
256 !-----------------------------------------------------------
257
258 return
259 end subroutine set_labels_spyros
260 end module readdata_spyros