Debian Codegraph @

src/read_data_snsph.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 THE SNSPH CODE
28 ! USING THE SELF-DESCRIBING FORMAT
29 !
30 ! the data is stored in the global array dat
31 !
32 ! >> this subroutine must return values for the following: <<
33 !
34 ! ncolumns : number of data columns
35 ! ndim, ndimV : number of spatial, velocity dimensions
36 ! nstepsread : number of steps read from this file
37 !
38 ! dat(maxplot,maxpart,maxstep) : main data array
39 !
40 ! npartoftype(1:6,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
49 module readdata_snsph
50 implicit none
51
52 public :: read_data_snsph, set_labels_snsph
53
54 private
55 contains
56
57
58 subroutine read_data_snsph(rootname,indexstart,ipos,nstepsread)
59 use particle_data
60 use params
61 use settings_data, only:ndim,ndimV,ncolumns,ncalc
62 use mem_allocation
63 integer, intent(in) :: indexstart,ipos
64 integer, intent(out) :: nstepsread
65 character(len=*), intent(in) :: rootname
66
67 integer :: j,ierr,ntoti,getcol
68 integer :: npart_max,nstep_max,ncolstep
69 real :: timei, gammai
70 logical :: iexist
71
72 character(len=len(rootname)+10) :: dumpfile
73
74 nstepsread = 0
75 npart_max = maxpart
76
77 dumpfile = trim(rootname)
78 !
79 !--check if first data file exists
80 !
81 inquire(file=dumpfile,exist=iexist)
82 if (.not.iexist) then
83 print "(a)",' *** error: ',trim(dumpfile),' file not found ***'
84 return
85 endif
86 !
87 !--fix number of spatial dimensions
88 !
89 ndim = 3
90 ndimV = 3
91 !
92 !--allocate memory initially
93 !
94 nstep_max = max(indexstart,1)
95
96 j = indexstart
97 nstepsread = 0
98
99 print "(1x,a)",'reading SNSPH format'
100 write(*,"(26('>'),1x,a,1x,26('<'))") trim(dumpfile)
101 !
102 !--read number of columns and number of particles
103 !
104 ncolstep = getcol()
105 call getdata(dumpfile,len_trim(dumpfile),npart_max,timei,gammai)
106
107 !
108 !--get number of particles from header and allocate memory
109 !
110 ntoti = npart_max
111 ncolumns = ncolstep
112
113 if (.not.allocated(dat) .or. ntoti > npart_max) then
114 npart_max = max(npart_max,INT(1.1*ntoti))
115 call alloc(npart_max,nstep_max,ncolstep+ncalc)
116 endif
117
118 npart_max = max(npart_max,ntoti)
119 !
120 !--allocate/reallocate memory if j > maxstep
121 !
122 if (j > maxstep) then
123 call alloc(maxpart,j+2*nstepsread,maxcol)
124 endif
125 !
126 !--now read the timestep data in the dumpfile
127 !
128 time(j) = timei
129
130 print "(a,i5,a,f10.3,a,i8)",'| step ',j,': t = ',time(j),' ntotal = ',ntoti
131
132 nstepsread = nstepsread + 1
133 !
134 !--set particle numbers
135 !
136 npartoftype(:,j) = 0
137 npartoftype(1,j) = ntoti
138 !
139 !--now read data
140 !
141 call readsdf(dumpfile,len_trim(dumpfile),dat(:,:,j),maxpart,maxcol,ierr)
142
143 if (nstepsread > 0 .and. j > 0) then
144 print*,'>> end of dump file: ntotal = ',sum(npartoftype(:,j))
145 endif
146
147 return
148
149 end subroutine read_data_snsph
150
151 !!------------------------------------------------------------
152 !! set labels for each column of data
153 !!------------------------------------------------------------
154
155 subroutine set_labels_snsph
156 use labels
157 use params
158 use settings_data
159 use geometry, only:labelcoord
160 integer :: i
161
162 if (ndim <= 0 .or. ndim > 3) then
163 print*,'*** ERROR: ndim = ',ndim,' in set_labels_snsph ***'
164 return
165 endif
166 if (ndimV <= 0 .or. ndimV > 3) then
167 print*,'*** ERROR: ndimV = ',ndimV,' in set_labels_snsph ***'
168 return
169 endif
170
171 do i=1,ndim
172 ix(i) = i
173 enddo
174 ivx = 4
175 ih = 10 ! smoothing length
176 iutherm = 8 ! thermal energy
177 ipmass = 7 ! particle mass
178 irho = 9 ! location of rho in data array
179
180 label(ix(1:ndim)) = labelcoord(1:ndim,1)
181 label(irho) = 'density'
182 label(iutherm) = 'temperature'
183 label(ih) = 'h'
184 label(ipmass) = 'particle mass'
185 !
186 !--set labels for vector quantities
187 !
188 iamvec(ivx:ivx+ndimV-1) = ivx
189 labelvec(ivx:ivx+ndimV-1) = 'v'
190 do i=1,ndimV
191 label(ivx+i-1) = trim(labelvec(ivx))//'\d'//labelcoord(i,1)
192 enddo
193 !
194 !--set labels for each particle type
195 !
196 ntypes = 1
197 labeltype(1) = 'gas'
198
199 !-----------------------------------------------------------
200
201 return
202 end subroutine set_labels_snsph
203 end module readdata_snsph