Debian Codegraph @

src/read_data_foulkes.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 STEVE FOULKES' ASCII DATA FORMAT
28 !
29 ! the data is stored in the global array dat
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 ! dat(maxplot,maxpart,maxstep) : main data array
38 !
39 ! npartoftype(1:6,maxstep) : number of particles of each type in each timestep
40 ! ntot(maxstep) : total number of particles 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
49
50 module readdata_foulkes
51 implicit none
52
53 public :: read_data_foulkes, set_labels_foulkes
54
55 private
56 contains
57
58 subroutine read_data_foulkes(rootname,indexstart,ipos,nstepsread)
59 use particle_data, only:dat,npartoftype,time,gamma,maxpart,maxcol,maxstep
60 use params
61 use settings_data, only:ndim,ndimV,ncolumns,ncalc,required,ipartialread,xorigin
62 use mem_allocation, only:alloc
63 use system_utils, only:lenvironment
64 use labels, only:ih
65 integer, intent(in) :: indexstart,ipos
66 integer, intent(out) :: nstepsread
67 character(len=*), intent(in) :: rootname
68 integer :: i,j,ierr,nerr,iunit,ncolstep
69 integer :: nprint,npart_max,nstep_max,icol
70 integer :: nmodel,nstar,ncolread
71 logical :: iexist
72 real :: tread,hmax,dtmin,tdg,hfac
73 real, dimension(3) :: xptmass,yptmass,vxptmass,vyptmass
74 character(len=len(rootname)+4) :: dumpfile
75
76 nstepsread = 0
77 nstep_max = 0
78 npart_max = maxpart
79 iunit = 15 ! logical unit number for input
80
81 dumpfile = trim(rootname)
82 !
83 !--check if first data file exists
84 !
85 inquire(file=dumpfile,exist=iexist)
86 if (.not.iexist) then
87 print "(a)",' *** error: '//trim(dumpfile)//': file not found ***'
88 return
89 endif
90 !
91 !--fix number of spatial dimensions (0 means no particle coords)
92 !
93 ndim = 3
94 ndimV = 3
95 nstar = 2
96
97 j = indexstart
98 nstepsread = 0
99 print "(a)",' Steve Foulkes/Carol Haswell/James Murray ascii data format'
100 write(*,"(26('>'),1x,a,1x,26('<'))") trim(dumpfile)
101
102 !
103 !--open the file and read the number of particles
104 !
105 open(unit=iunit,iostat=ierr,file=dumpfile,status='old',form='formatted')
106 if (ierr /= 0) then
107 print "(a)",'*** ERROR OPENING '//trim(dumpfile)//' ***'
108 return
109 endif
110 !
111 !--read header line, set time
112 !
113 read(iunit,*,iostat=ierr) nmodel,nprint,hmax,tread,dtmin,tdg
114 if (ierr /= 0) print "(a)",' WARNING: error(s) reading first header line'
115 print "(a,1pe10.3,a,i10,a,i10)",' time = ',tread,' npart =',nprint,' model number = ',nmodel
116 print "(3(a,1pe10.4))",' hmax = ',hmax,' dtmin = ',dtmin,' tdg = ',tdg
117 !
118 !--determine how many columns we are going to read
119 !
120 if (lenvironment('FSPLASH_READALL')) then
121 ncolstep = 26
122 print "(a)",' reading all columns'
123 else
124 ncolstep = 15
125 print "(a,i2)",' reading only to column 15 (use --readall to read all)'
126 endif
127 !
128 !--(re)allocate memory
129 !
130 nstep_max = max(maxstep,nstep_max,indexstart,1)
131 if (.not.allocated(dat) .or. (nprint > maxpart) .or. (ncolstep+ncalc) > maxcol) then
132 npart_max = max(npart_max,nprint+nstar,maxpart)
133 !--allow extra room if reallocating
134 if (allocated(dat)) npart_max = max(npart_max,INT(1.1*(nprint+nstar)),maxpart)
135 call alloc(npart_max,nstep_max,max(ncolstep+ncalc,maxcol))
136 endif
137 !
138 !--set the necessary parameters
139 !
140 ncolumns = ncolstep
141 nstepsread = nstepsread + 1
142 npartoftype(:,j) = 0
143 npartoftype(1,j) = nprint
144 npartoftype(2,j) = nstar
145 time(j) = tread
146 gamma(j) = 5./3.
147 !
148 !--now read the timestep data in the dumpfile
149 !
150 nerr = 0
151 !
152 !--only read required columns
153 !
154 ncolread = 0
155 do i=1,ncolstep
156 if (required(i)) ncolread = i
157 enddo
158 if (ncolread /= ncolstep) then
159 ipartialread = .true.
160 print*,' reading only up to column ',ncolread
161 endif
162
163 do i=1,nprint
164 read(iunit,*,iostat=ierr) (dat(i,icol,j),icol = 1,ncolread)
165 if (ierr /= 0) nerr = nerr + 1
166 enddo
167 if (nerr > 0) print *,' ERRORS reading particle data on ',nerr,' lines'
168 !
169 !--read point mass information
170 !
171 read(iunit,*,iostat=ierr) xptmass(1),yptmass(1),xptmass(2),yptmass(2),hfac
172 !--point mass velocities not read, though would put them here if they were
173 vxptmass(1) = 0.
174 vyptmass(1) = 0.
175 vxptmass(2) = 0.
176 vyptmass(2) = 0.
177 if (ierr /= 0) print *,' ERROR reading primary and secondary positions'
178
179 close(iunit)
180
181 !--set labels to get ih for setting smoothing length of stars
182 call set_labels_foulkes
183
184 !--copy star particle properties into main data array
185 do i=nprint+1,nprint+nstar
186 dat(i,1,j) = xptmass(i-nprint)
187 dat(i,2,j) = yptmass(i-nprint)
188 dat(i,3,j) = 0.
189 dat(i,4,j) = vxptmass(i-nprint)
190 dat(i,5,j) = vyptmass(i-nprint)
191 dat(i,6,j) = 0.
192 dat(i,7:ncolstep,j) = 0.
193 if (ih > 0) dat(i,ih,j) = epsilon(0.) ! small but non-zero smoothing length
194 enddo
195 print "(' primary (x,y) = (',1pe10.2,',',1pe10.2,')')",xptmass(1),yptmass(1)
196 print "(' secondary (x,y) = (',1pe10.2,',',1pe10.2,')')",xptmass(2),yptmass(2)
197 print "(a)",' setting origin to primary position... '
198 xorigin(1) = xptmass(1)
199 xorigin(2) = yptmass(1)
200 xorigin(3) = 0.
201
202
203 return
204 end subroutine read_data_foulkes
205
206 !!-------------------------------------------------------------------
207 !! set labels for each column of data
208 !!
209 !! read these from a file called 'columns' in the current directory
210 !! then take sensible guesses as to which quantities are which
211 !! from the column labels
212 !!
213 !!-------------------------------------------------------------------
214
215 subroutine set_labels_foulkes
216 use labels, only:label,labeltype,ix,irho,ipmass,ih,ivx,iamvec,labelvec,make_vector_label
217 use params
218 use settings_data, only:ntypes,ndim,ndimV,UseTypeInRenderings
219 use geometry, only:labelcoord
220 integer :: i,ifx
221
222 do i=1,ndim
223 ix(i) = i
224 enddo
225 ivx = ndim+1
226 ipmass = ivx+ndimV
227 ifx = ipmass+1
228 irho = ifx+ndimV
229 label(irho+1) = 'du/dt'
230 label(irho+2) = 'C_{s}'
231 label(irho+3) = 'alpha'
232 ih = irho+4
233 label(irho+5) = 'kpc'
234 label(irho+6) = 'schb'
235 label(irho+7) = 'dtp'
236 label(irho+8) = 'sigma'
237 label(irho+9) = 'pdr2'
238 label(irho+10) = 'av_sep'
239 label(irho+11) = 'radius'
240 label(irho+12) = 'viscosity flag'
241 label(irho+13) = 'neighbour number'
242 label(irho+14) = 'iwas'
243 label(irho+15) = 'll'
244 if (irho > 0) label(irho) = 'density'
245 if (ih > 0) label(ih) = 'smoothing length'
246 if (ipmass > 0) label(ipmass) = 'particle mass'
247 call make_vector_label('v',ivx,ndimV,iamvec,labelvec,label,labelcoord(:,1))
248 call make_vector_label('f',ifx,ndimV,iamvec,labelvec,label,labelcoord(:,1))
249 !
250 !--set labels for each particle type
251 !
252 ntypes = 2
253 labeltype(1) = 'gas'
254 labeltype(2) = 'star'
255 UseTypeInRenderings(1) = .true.
256 UseTypeInRenderings(2) = .false.
257
258 end subroutine set_labels_foulkes
259 end module readdata_foulkes