Debian Codegraph @

src/read_data_jjm.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 JOE'S 2D SPH CODE
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 ! maxplot,maxpart,maxstep : dimensions of main data array
38 ! dat(maxplot,maxpart,maxstep) : main data array
39 !
40 ! npartoftype(1:6,maxstep) : number of particles of each type in each timestep
41 ! ntot(maxstep) : total number of particles in each timestep
42 ! iam(maxpart,maxstep): integer identification of particle type
43 !
44 ! time(maxstep) : time at each step
45 ! gamma(maxstep) : gamma at each step
46 !
47 ! most of these values are stored in global arrays
48 ! in the module 'particle_data'
49 !-------------------------------------------------------------------------
50
51 module readdata_jjm
52 implicit none
53
54 public :: read_data_jjm, set_labels_jjm
55
56 private
57 contains
58
59 subroutine read_data_jjm(rootname,indexstart,ipos,nstepsread)
60 use particle_data
61 use params
62 use settings_data, only:ndim,ndimV,ncolumns
63 use mem_allocation
64 integer, intent(IN) :: indexstart,ipos
65 integer, intent(OUT) :: nstepsread
66 character(LEN=*), intent(IN) :: rootname
67 integer :: i,j,ifile,ierr
68 integer :: istep,nprint,npart_max,nstep_max,icol
69 logical :: iexist
70 character(LEN=LEN(rootname)+4) :: dumpfile
71 real :: timei,dti,hi
72
73 nstepsread = 0
74 nstep_max = 0
75 npart_max = maxpart
76 ifile = 1
77
78 dumpfile = trim(rootname)
79 ! if (index(dumpfile,'.plt')==0) dumpfile = trim(rootname)//'.plt'
80 !
81 !--check if first data file exists
82 !
83 inquire(file=dumpfile,exist=iexist)
84 if (.not.iexist) then
85 print "(a)",' *** error: ',trim(dumpfile),' file not found ***'
86 return
87 endif
88 !
89 !--fix number of spatial dimensions
90 !
91 ndim = 2
92 ndimV = 2
93 ncolumns = 7 ! number of columns in file
94 !
95 !--allocate memory initially
96 !
97 nstep_max = max(nstep_max,indexstart,2)
98
99 j = indexstart
100 nstepsread = 0
101
102 print "(1x,a)",'reading Joe Monaghan ascii format'
103 write(*,"(26('>'),1x,a,1x,26('<'))") trim(dumpfile)
104 !
105 !--open the file and read the number of particles
106 !
107 open(unit=15,iostat=ierr,file=dumpfile,status='old',form='formatted')
108 if (ierr /= 0) then
109 print*,'*** ERROR OPENING ',trim(dumpfile),' ***'
110 else
111 !
112 !--read the number of particles in the first step,
113 ! allocate memory and rewind
114 !
115 read(15,*,end=55,iostat=ierr) istep,nprint,timei,dti
116 print*,'first time = ',timei,nprint
117 if (.not.allocated(dat) .or. (nprint > npart_max)) then
118 npart_max = max(npart_max,INT(1.1*(nprint)))
119 call alloc(npart_max,nstep_max,ncolumns)
120 endif
121 rewind(15)
122 endif
123 if (ierr /= 0) then
124 print*,'*** ERROR READING TIMESTEP HEADER ***'
125 else
126
127 oversteps: do
128 !
129 !--loop over the timesteps in this file
130 !
131 npart_max = max(npart_max,nprint)
132 !
133 !--allocate/reallocate memory if j > maxstep
134 !
135 if (j > maxstep) then
136 call alloc(maxpart,2*j,maxcol)
137 endif
138 !
139 !--now read the timestep data in the dumpfile
140 !
141 read(15,*,end=55,iostat=ierr) istep,nprint,hi,time(j),dti
142 do i=1,nprint
143 read(15,*,end=55,iostat=ierr) (dat(i,icol,j),icol = 1,ncolumns)
144 enddo
145 masstype(1,j) = 1.
146
147 if (ierr /= 0) then
148 print "(a)",'|*** ERROR READING TIMESTEP ***'
149 return
150 else
151 nstepsread = nstepsread + 1
152 endif
153
154 npartoftype(:,j) = 0
155 npartoftype(1,j) = nprint
156
157 print*,j,' time = ',time(j)
158 gamma(j) = 1.666666666667
159 j = j + 1
160
161 enddo oversteps
162 endif
163
164 55 continue
165 !
166 !--reached end of file
167 !
168 close(15)
169
170 print*,'nstepsread = ',nstepsread
171 print*,'>> end of dump file: nsteps =',j-1,'ntot = ',npartoftype(1,j-1),'nptmass=',npartoftype(2,j-1)
172
173 return
174
175 end subroutine read_data_jjm
176
177 !!------------------------------------------------------------
178 !! set labels for each column of data
179 !!------------------------------------------------------------
180
181 subroutine set_labels_jjm
182 use labels
183 use params
184 use settings_data
185 use geometry, only:labelcoord
186 integer :: i
187
188 if (ndim <= 0 .or. ndim > 3) then
189 print*,'*** ERROR: ndim = ',ndim,' in set_labels_jjm ***'
190 return
191 endif
192 if (ndimV <= 0 .or. ndimV > 3) then
193 print*,'*** ERROR: ndimV = ',ndimV,' in set_labels_jjm ***'
194 return
195 endif
196
197 do i=1,ndim
198 ix(i) = i
199 enddo
200 label(ix(1:ndim)) = labelcoord(1:ndim,1)
201 ivx = ndim+1
202 ipr = ndim+ndimV+2
203 ih = ndim+ndimV+3 ! smoothing length
204 label(ih) = 'h'
205 irho = ndim+ndimV+1 ! location of rho in data array
206 label(irho) = 'density'
207 if (ipr > 0) label(ipr) = 'pressure'
208 iutherm = 0 ! thermal energy
209 ! label(iutherm) = 'u'
210 ipmass = 0 ! particle mass
211 ! label(ipmass) = 'particle mass'
212
213 iamvec(ivx:ivx+ndimV-1) = ivx
214 labelvec(ivx:ivx+ndimV-1) = 'v'
215 do i=1,ndimV
216 label(ivx+i-1) = 'v\d'//labelcoord(i,1)
217 enddo
218 !
219 !--set labels for each particle type
220 !
221 ntypes = 1 !!maxparttypes
222 labeltype(1) = 'gas'
223 UseTypeInRenderings(1) = .true.
224
225 !-----------------------------------------------------------
226
227 return
228 end subroutine set_labels_jjm
229 end module readdata_jjm