Debian Codegraph @

src/read_data_seren.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-2013 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 OUTPUT FROM THE SEREN CODE
28 ! HANDLES BOTH ASCII AND BINARY FILES
29 !
30 ! THE FOLLOWING ENVIRONMENT VARIABLES AFFECT THIS FORMAT:
31 !
32 ! DSPLASH_EXTRACOLS : set to number of extra columns to read (after itype)
33 !
34 ! the data is stored in the global array dat
35 !
36 ! >> this subroutine must return values for the following: <<
37 !
38 ! ncolumns : number of data columns
39 ! ndim, ndimV : number of spatial, velocity dimensions
40 ! nstepsread : number of steps read from this file
41 !
42 ! dat(maxpart,maxplot,maxstep) : main data array
43 !
44 ! npartoftype(maxstep): number of particles of each type in each timestep
45 !
46 ! time(maxstep) : time at each step
47 ! gamma(maxstep) : gamma at each step
48 ! (used in calc_quantities for calculating the pressure)
49 !
50 ! most of these values are stored in global arrays
51 ! in the module 'particle_data'
52 !
53 ! Partial data read implemented means that columns with
54 ! the 'required' flag set to false are not read (read is therefore much faster)
55 !-------------------------------------------------------------------------
56
57 module seren_data_store
58 implicit none
59 integer :: seren_maxparttypes ! Number of types we are using
60
61 character(len=20) :: format_id ! File format (for verification)
62 integer :: nunits ! Number of units
63 integer :: ndata ! Number of data entries
64 integer :: ptot, stot ! Number of particles/sinks
65 integer :: pboundary, picm, pgas ! Number of each type of particle
66 integer :: pcdm, pdust, pion ! Number of each type of particle
67 integer :: PR, NDIMtemp, VDIMtemp, BDIMtemp ! Important parameters
68 integer :: dmdt_range ! DMDT_RANGE
69 character(len=20) :: data_id(1:500) ! Char ids of arrays written
70 character(len=20) :: unit_data(1:500) ! Unit data
71 real :: unit_coeff(1:500) ! Unit multiplier
72 integer :: typedata(1:5,1:500) ! type data header array
73 integer :: itemp, iporig ! Since SPLASH does not have one
74 integer :: iunknown(1:1000) ! For unknown data types
75 character(len=20) :: r_unit ! length unit
76 character(len=20) :: m_unit ! mass unit
77 character(len=20) :: rho_unit ! density unit
78 character(len=20) :: h_unit ! smoothing length unit
79 integer, parameter :: DP = selected_real_kind(p=15) ! double precision
80 integer, parameter :: SP = selected_real_kind(p=6) ! single precision
81 integer, parameter :: ILP = selected_int_kind(r=15) ! Integer long precision
82
83 ! Length units in metres
84 real(kind=DP),parameter :: r_pc = 3.08568E16_DP ! parsec
85 real(kind=DP),parameter :: r_au = 1.49597870E11_DP ! astronomical unit
86 real(kind=DP),parameter :: r_sun = 6.96E8_DP ! solar radius
87 real(kind=DP),parameter :: r_earth = 6.371E6_DP ! Earth radius
88
89 ! Mass units in kilograms
90 real(kind=DP),parameter :: m_sun = 1.98892E30_DP ! solar mass
91 real(kind=DP),parameter :: m_jup = 1.8986E27_DP ! Jupiter mass
92 real(kind=DP),parameter :: m_earth = 5.9736E24_DP ! Earth mass
93
94 ! Time units in seconds
95 real(kind=DP),parameter :: myr = 3.1556952E13_DP ! megayear
96 real(kind=DP),parameter :: yr = 3.1556952E7_DP ! year
97 real(kind=DP),parameter :: day = 8.64E4_DP ! day
98
99 end module seren_data_store
100
101
102 module readdata_seren
103 implicit none
104
105 public :: read_data_seren, set_labels_seren
106
107 private
108 contains
109
110 subroutine read_data_seren(rootname,istepstart,ipos,nstepsread)
111 use particle_data, only:dat,iamtype,npartoftype,time,gamma,maxpart,maxcol,maxstep,headervals
112 use params
113 use settings_data, only:ndim,ndimV,ncolumns,ncalc,ipartialread,ntypes
114 use settings_units, only:unitzintegration, unit_interp
115 use mem_allocation, only:alloc
116 use labels, only:labeltype,labelzintegration,headertags,print_types
117 use system_utils, only:ienvironment
118 use seren_data_store
119 use asciiutils, only:make_tags_unique
120 integer, intent(in) :: istepstart,ipos
121 integer, intent(out) :: nstepsread
122 character(len=*), intent(in) :: rootname
123 character(len=len(rootname)+10) :: datfile
124 integer, parameter :: iunit = 16
125 integer :: i,j,step,ierr,iambinaryfile,itype
126 integer :: npart_max,nstep_max
127 logical :: iexist,reallocate,doubleprec
128 character(len=50) :: string
129
130 integer :: idata(1:50)
131 integer (kind=ILP) :: ilpdata(1:50)
132 real :: rdata(1:50)
133 real(doub_prec) :: rdata_dp(1:50)
134 real(doub_prec) :: dpdata(1:50)
135 real :: timetemp,gammatemp
136
137 unit_coeff = 1. ! not yet used
138 m_unit = ""
139 rho_unit = ""
140 h_unit = ""
141 !iRescale = .TRUE.
142 ipartialread = .false. ! we always read full data file
143
144 seren_maxparttypes = min(maxparttypes,7)
145 nstepsread = 0
146
147 if (len_trim(rootname) > 0) then
148 datfile = trim(rootname)
149 else
150 print*,' **** no data read **** '
151 return
152 endif
153 !
154 !--check if first data file exists
155 !
156 inquire(file=datfile,exist=iexist)
157 if (.not.iexist) then
158 print "(a)",' *** error: '//trim(datfile)//': file not found ***'
159 return
160 endif
161
162 !
163 !--read data from snapshots
164 !
165 step = istepstart
166
167 write(*,"(23('-'),1x,a,1x,23('-'))") trim(datfile)
168 !
169 !--open data file and read data
170 !
171 !
172 !--determine whether file is binary or ascii, open it and read the header
173 !
174 ! Try binary first, then ascii
175 open(unit=iunit,file=datfile,status='old',form='unformatted',iostat=ierr)
176
177 if (ierr /= 0) then
178 print "(a)",'*** ERROR OPENING '//trim(datfile)//' ***'
179 return
180 endif
181 !
182 !--read the file header
183 ! try binary format first, and if unsuccessful try ascii
184 !
185 read (unit=iunit,iostat=ierr) format_id
186 if (ierr /= 0 .OR. index(format_id,'BINARYDUMP')==0) then
187 ! Ascii format
188 iambinaryfile = 0
189 close (unit=iunit)
190 open(unit=iunit,file=datfile,status='old',form='formatted',iostat=ierr)
191 if (ierr /= 0) then
192 print "(a)",'*** ERROR OPENING '//trim(datfile)//' AS ASCII ***'
193 return
194 endif
195 rewind(unit=iunit)
196 read (unit=iunit,fmt=*,iostat=ierr) format_id
197 if (ierr /= 0) then
198 print "(a)",'*** ERROR OPENING '//trim(datfile)//' - UNKNOWN FILE FORMAT '//format_id//' ***'
199 return
200 endif
201 if (trim(adjustl(format_id)) /= "SERENASCIIDUMPV2") then
202 print "(a)",'*** ERROR OPENING '//trim(datfile)//' AS ASCII - WRONG FILE FORMAT ***'
203 return
204 endif
205 elseif (format_id(1:7)=='NBINARY') then
206 ! format is SEREN v3 which does not contain the 4byte Fortran tags
207 close (unit=iunit)
208 !print "(a)",' attempting to read Seren v3 format'
209 open(unit=iunit,file=datfile,status='old',form='unformatted',access='stream',iostat=ierr)
210 if (ierr /= 0) then
211 print "(a)",'*** ERROR OPENING '//trim(datfile)//' - UNKNOWN FILE FORMAT '//format_id//' ***'
212 return
213 endif
214 read (unit=iunit,iostat=ierr) format_id
215 !print "(a)",trim(format_id)
216 iambinaryfile = 2
217 print "(a)",' reading binary seren v3 format '
218 else
219 iambinaryfile = 1
220 print "(a)",' reading binary seren v2 format '
221 endif
222
223 if (iambinaryfile >= 1) then
224 read (iunit) PR
225 read (iunit) NDIMtemp
226 read (iunit) VDIMtemp
227 read (iunit) BDIMtemp
228 else
229 print "(a)",' reading ascii seren v2 format '
230 read (iunit,*) PR
231 read (iunit,*) NDIMtemp
232 read (iunit,*) VDIMtemp
233 read (iunit,*) BDIMtemp
234 endif
235
236 if (iambinaryfile==0) then
237 ! Don't care about precision
238 doubleprec = .FALSE.
239 elseif (PR == 8 .OR. PR == 2) then
240 ! Double precision file
241 print "(a)",' Double precision file'
242 doubleprec = .TRUE.
243 elseif (PR == 4 .OR. PR == 1) then
244 ! Single precision file
245 print "(a)",' Single precision file'
246 doubleprec = .FALSE.
247 else
248 print "(a)",'*** WARNING OPENING '//trim(datfile)//' - ASSUMING SINGLE PRECISION ***'
249 doubleprec = .FALSE.
250 endif
251
252 typedata = 0
253
254 if (iambinaryfile>=1) then
255 call read_serenheader_binary(iunit)
256 elseif (iambinaryfile==0) then
257 call read_serenheader_ascii(iunit)
258 endif
259 !
260 !--get values of quantities from the header
261 !
262 ndim = NDIMtemp
263 ndimv = VDIMtemp
264
265 ptot = idata(1)
266 stot = idata(2)
267 pboundary = idata(3)
268 picm = idata(4)
269 pgas = idata(5)
270 pcdm = idata(6)
271 pdust = idata(7)
272 pion = idata(8)
273 dmdt_range = idata(30)
274 !print*,' GOT ',idata(:),data(:)
275
276 !--check for errors in integer header (either from corrupt file or wrong endian)
277 if (ptot+stot <= 0 .or. ptot+stot > 1.e10) then
278 if (iambinaryfile>=1) then
279 print "(a)",' ERROR reading binary file header: wrong endian? '
280 else
281 print "(a)",' ERROR reading ascii file header '
282 endif
283 close(unit=iunit)
284 return
285 endif
286
287 timetemp = real(dpdata(1))
288 gammatemp = 1. ! Not saved in file
289
290 print*,'time : ',timetemp
291 print*,'gamma : ',gammatemp
292 print*,'n_total : ',ptot
293
294 call set_labels_seren
295 !
296 !--if successfully read header, increment the nstepsread counter
297 !
298 nstepsread = nstepsread + 1
299 !
300 !-- now work out dimensionless weight unit and z integration unit
301 !
302 call find_weights(unit_interp,unitzintegration,labelzintegration)
303 !
304 !--now read data
305 !
306 reallocate = .false.
307 npart_max = maxpart
308 nstep_max = max(maxstep,1)
309
310 if ((ptot+stot) > maxpart) then
311 reallocate = .true.
312 if (maxpart > 0) then
313 ! if we are reallocating, try not to do it again
314 npart_max = int(1.1*(ptot+stot))
315 else
316 ! if first time, save on memory
317 npart_max = int(ptot+stot)
318 endif
319 endif
320 if (step >= maxstep .and. step /= 1) then
321 nstep_max = step + max(10,INT(0.1*nstep_max))
322 reallocate = .true.
323 endif
324 !
325 !--reallocate memory for main data array
326 !
327 if (reallocate .or. .not.(allocated(dat))) then
328 call alloc(npart_max,nstep_max,max(ncolumns+ncalc,maxcol),mixedtypes=.true.)
329 endif
330 !
331 !--copy header into header arrays
332 !
333 npartoftype(:,step) = 0
334 ! npartoftype(1,step) = ptot
335 time(step) = timetemp
336 gamma(step) = gammatemp
337
338 !--identify integer header variables and copy into headervals
339 headertags(1:8) = (/'ptot ','stot ','pboundary ','picm ',&
340 'pgas ','pcdm ','pdust ','pion '/)
341 headervals(1:8,step) = real(idata(1:8))
342
343 !--tag double precision header variables with "dp_data1,dp_data2 etc."
344 do j=1,size(dpdata)
345 headertags(8+j) = 'dp_data'
346 headervals(8+j,step) = dpdata(j)
347 enddo
348 call make_tags_unique(8+size(dpdata),headertags)
349 !
350 !--read particle data
351 !
352 if (ptot > 0) then
353 call read_serenbody(iunit,ierr)
354 else
355 ptot = 0
356 dat(:,:,step) = 0.
357 endif
358
359 call set_types(iamtype(:,step),ptot+stot,npartoftype(:,step))
360 if (any(npartoftype(2:,step) /= 0)) call print_types(npartoftype(:,step),labeltype)
361 !
362 !--close data file and return
363 !
364 close(unit=iunit)
365
366 return
367
368 contains
369
370 !----------------------------------------------------
371 ! binary header read
372 !----------------------------------------------------
373 subroutine read_serenheader_binary(iunitb)
374 integer, intent(in) :: iunitb
375
376 read (iunitb,end=55) idata
377 read (iunitb,end=55) ilpdata
378 if (doubleprec) then
379 read (iunitb,end=55) rdata_dp
380 else
381 read (iunitb,end=55) rdata
382 endif
383 read (iunitb,end=55) dpdata
384
385 ndata = idata(21)
386 nunits = idata(20)
387
388 if (nunits > 0) read (iunitb) unit_data(1:nunits)
389 if (ndata > 0) read (iunitb) data_id(1:ndata)
390 if (ndata > 0) read (iunitb) typedata(1:5,1:ndata)
391
392 return
393
394 55 continue
395 print "(a)",' ERROR: end of file in binary header read'
396 stop
397 !return
398
399 end subroutine read_serenheader_binary
400
401 !----------------------------------------------------
402 ! ascii header read
403 !----------------------------------------------------
404 subroutine read_serenheader_ascii(iunita)
405 integer, intent(in) :: iunita
406
407 do i=1,size(idata)
408 read (iunita,*,end=55) idata(i)
409 enddo
410
411 do i=1,size(ilpdata)
412 read (iunita,*,end=55) ilpdata(i)
413 enddo
414
415 do i=1,size(rdata)
416 read (iunita,*,end=55) rdata(i)
417 enddo
418
419 do i=1,size(dpdata)
420 read (iunita,*,end=55) dpdata(i)
421 enddo
422
423 ndata = idata(21)
424 nunits = idata(20)
425
426 do i=1,nunits
427 read (iunita,'(A)') unit_data(i)
428 enddo
429 do i=1,ndata
430 read (iunita,'(A)') data_id(i)
431 enddo
432 do i=1,ndata
433 read (iunita,*) typedata(1:5,i)
434 enddo
435
436 return
437
438 55 continue
439 print "(a)",' ERROR: end of file in ascii header read'
440 stop
441 !return
442
443 end subroutine read_serenheader_ascii
444
445 !----------------------------------------------------
446 ! body read
447 !----------------------------------------------------
448
449 subroutine read_serenbody(iunit,ierr_out)
450 use seren_data_store
451 use labels, only:ix,ivx,ipmass,ih,irho,iBfirst,iutherm
452 integer, intent(in) :: iunit
453 integer, intent(out) :: ierr_out
454 integer :: ierr, ierr1
455 integer :: j, k
456 integer, dimension(:), allocatable :: dummy_int
457 integer, dimension(:,:), allocatable :: dummy_int_2D
458 real(kind=SP), dimension(:,:), allocatable :: dummy
459 real(kind=DP), dimension(:,:), allocatable :: dummy_dp
460 real(kind=SP), dimension(:), allocatable :: dummy_scalar
461 real(kind=DP), dimension(:), allocatable :: dummy_dp_scalar
462 integer(kind=ILP), dimension(:), allocatable :: dummy_ilp_int
463 logical, dimension(:), allocatable :: dummy_logical
464 integer(kind=ILP), dimension(:,:), allocatable :: dummy_ilp_int_2D
465 logical, dimension(:,:), allocatable :: dummy_logical_2D
466 logical :: ldummy(1:2)
467 integer :: idummy2(1:2)
468 real(kind=SP), allocatable :: raux(:)
469 real(kind=DP), allocatable :: raux_dp(:)
470 real, allocatable :: sink_dat_array(:,:,:)
471 integer :: s
472 integer :: unknown
473 integer :: pfirst
474 integer :: plast
475 integer :: width
476 integer :: typecode
477 integer :: unit_id
478 integer :: sink_data_length
479 character(len=30) :: sink_format_string
480 character(len=50) :: format_string
481 integer :: nl,ni,nli,npr,ndp,nchar
482 logical, allocatable :: l_data_st(:)
483 integer, allocatable :: i_data_st(:)
484 integer(kind=ILP), allocatable :: ilp_data_st(:)
485 real(kind=SP), allocatable :: sp_data_st(:)
486 real(kind=DP), allocatable :: dp_data_st(:)
487 real(kind=DP), allocatable :: dp_data_st2(:)
488
489 unknown = 0
490
491 if (stot>0) then
492 sink_data_length = 11+NDIMtemp+VDIMtemp+2*dmdt_range
493 allocate(raux(1:sink_data_length))
494 if (doubleprec) allocate(raux_dp(1:sink_data_length))
495 allocate(sink_dat_array(1:stot,1:ncolumns,1))
496 sink_dat_array = 0.
497 write (sink_format_string,'(A,I0,A)') "(", sink_data_length, "E18.10)"
498 endif
499
500 ierr_out = 0
501
502 allocate(dummy_int(1:ptot),stat=ierr)
503 if (ierr /= 0) then
504 print *,' ERROR allocating memory'
505 goto 56
506 endif
507 if (doubleprec) allocate(dummy_dp_scalar(1:ptot),stat=ierr)
508 if (ierr /= 0) then
509 print *,' ERROR allocating memory'
510 goto 56
511 endif
512 allocate(dummy_scalar(1:ptot),stat=ierr)
513 if (ierr /= 0) then
514 print *,' ERROR allocating memory'
515 goto 56
516 endif
517
518 write (6,'(A,A)',ADVANCE="NO") "Loading: "
519 do i=1,ndata
520 if (i==1) then
521 write (6,'(A)',ADVANCE="NO") trim(data_id(i))
522 else
523 write (6,'(A,A)',ADVANCE="NO") ", ", trim(data_id(i))
524 endif
525 select case (trim(data_id(i)))
526 case ("porig")
527 ! Original particle number
528 ! Read through porig numbers
529 pfirst = typedata(2,i); plast = typedata(3,i)
530 if (iambinaryfile>=1) then
531 read(iunit,end=55,iostat=ierr) dummy_int(pfirst:plast)
532 else
533 do k=pfirst,plast
534 read(iunit,fmt=*,end=55,iostat=ierr1) dummy_int(k)
535 if (ierr1 /= 0) ierr = ierr1
536 enddo
537 endif
538 if (ierr /= 0) then
539 print*,' WARNING: errors reading through porig '
540 ierr_out = -1
541 endif
542 do k=pfirst,plast
543 dat(k,iporig,step) = real(dummy_int(k))
544 enddo
545 if (ierr /= 0) then
546 print*,' WARNING: errors reading unknown data type ', trim(data_id(i))
547 ierr_out = -1
548 endif
549 case ("r")
550 ! Position
551 if (doubleprec) allocate(dummy_dp(1:NDIMtemp,1:ptot),stat=ierr)
552 allocate(dummy(1:NDIMtemp,1:ptot),stat=ierr)
553 pfirst = typedata(2,i); plast = typedata(3,i)
554 if (iambinaryfile>=1) then
555 if (doubleprec) then
556 read(iunit,end=55,iostat=ierr) dummy_dp(1:NDIMtemp,pfirst:plast)
557 dummy(1:NDIMtemp,pfirst:plast) = real(dummy_dp(1:NDIMtemp,pfirst:plast))
558 else
559 read(iunit,end=55,iostat=ierr) dummy(1:NDIMtemp,pfirst:plast)
560 endif
561 else
562 do k=pfirst,plast
563 read(iunit,*,end=55,iostat=ierr1) dummy(1:NDIMtemp,k)
564 if (ierr1 /= 0) ierr = ierr1
565 enddo
566 endif
567 do k=pfirst,plast
568 dat(k,ix(1):ix(1)+NDIMtemp-1,step) = dummy(1:NDIMtemp,k)
569 enddo
570 if (ierr /= 0) then
571 print*,' WARNING: errors reading positions '
572 ierr_out = -1
573 endif
574 deallocate(dummy)
575 if (doubleprec) deallocate(dummy_dp)
576 case ("h")
577 ! Smoothing lengths
578 pfirst = typedata(2,i); plast = typedata(3,i)
579 if (iambinaryfile>=1) then
580 if (doubleprec) then
581 read(iunit,end=55,iostat=ierr) dummy_dp_scalar(pfirst:plast)
582 dummy_scalar(pfirst:plast) = real(dummy_dp_scalar(pfirst:plast))
583 else
584 read(iunit,end=55,iostat=ierr) dummy_scalar(pfirst:plast)
585 endif
586 else
587 do k=pfirst,plast
588 read(iunit,*,end=55,iostat=ierr1) dummy_scalar(k)
589 if (ierr1 /= 0) ierr = ierr1
590 enddo
591 endif
592 do k=pfirst,plast
593 dat(k,ih,step) = dummy_scalar(k)
594 enddo
595 if (ierr /= 0) then
596 print*,' WARNING: errors reading smoothing lengths'
597 ierr_out = -1
598 endif
599 case ("m")
600 ! Mass
601 pfirst = typedata(2,i); plast = typedata(3,i)
602 if (iambinaryfile>=1) then
603 if (doubleprec) then
604 read(iunit,end=55,iostat=ierr) dummy_dp_scalar(pfirst:plast)
605 dummy_scalar(pfirst:plast) = real(dummy_dp_scalar(pfirst:plast))
606 else
607 read(iunit,end=55,iostat=ierr) dummy_scalar(pfirst:plast)
608 endif
609 else
610 do k=pfirst,plast
611 read(iunit,*,end=55,iostat=ierr1) dummy_scalar(k)
612 if (ierr1 /= 0) ierr = ierr1
613 enddo
614 endif
615 do k=pfirst,plast
616 dat(k,ipmass,step) = dummy_scalar(k)
617 enddo
618 if (ierr /= 0) then
619 print*,' WARNING: errors reading masses'
620 ierr_out = -1
621 endif
622 case ("v")
623 ! Velocities
624 if (doubleprec) allocate(dummy_dp(1:VDIMtemp,1:ptot),stat=ierr)
625 allocate(dummy(1:VDIMtemp,1:ptot),stat=ierr)
626 pfirst = typedata(2,i); plast = typedata(3,i)
627 if (iambinaryfile>=1) then
628 if (doubleprec) then
629 read(iunit,end=55,iostat=ierr) dummy_dp(1:VDIMtemp,pfirst:plast)
630 dummy(1:VDIMtemp,pfirst:plast) = real(dummy_dp(1:VDIMtemp,pfirst:plast))
631 else
632 read(iunit,end=55,iostat=ierr) dummy(1:VDIMtemp,pfirst:plast)
633 endif
634 else
635 do k=pfirst,plast
636 read(iunit,*,end=55,iostat=ierr1) dummy(1:VDIMtemp,k)
637 if (ierr1 /= 0) ierr = ierr1
638 enddo
639 endif
640 do k=pfirst,plast
641 dat(k,ivx:ivx+VDIMtemp-1,step) = dummy(1:VDIMtemp,k)
642 enddo
643 if (ierr /= 0) then
644 print*,' WARNING: errors reading velocities '
645 ierr_out = -1
646 endif
647 deallocate(dummy)
648 if (doubleprec) deallocate(dummy_dp)
649 case ("rho")
650 ! Densities
651 pfirst = typedata(2,i); plast = typedata(3,i)
652 if (iambinaryfile>=1) then
653 if (doubleprec) then
654 read(iunit,end=55,iostat=ierr) dummy_dp_scalar(pfirst:plast)
655 dummy_scalar(pfirst:plast) = real(dummy_dp_scalar(pfirst:plast))
656 else
657 read(iunit,end=55,iostat=ierr) dummy_scalar(pfirst:plast)
658 endif
659 else
660 do k=pfirst,plast
661 read(iunit,*,end=55,iostat=ierr1) dummy_scalar(k)
662 if (ierr1 /= 0) ierr = ierr1
663 enddo
664 endif
665 do k=pfirst,plast
666 dat(k,irho,step) = dummy_scalar(k)
667 enddo
668 if (ierr /= 0) then
669 print*,' WARNING: errors reading densities'
670 ierr_out = -1
671 endif
672 case ("temp")
673 ! Temperatures
674 pfirst = typedata(2,i); plast = typedata(3,i)
675 if (iambinaryfile>=1) then
676 if (doubleprec) then
677 read(iunit,end=55,iostat=ierr) dummy_dp_scalar(pfirst:plast)
678 dummy_scalar(pfirst:plast) = real(dummy_dp_scalar(pfirst:plast))
679 else
680 read(iunit,end=55,iostat=ierr) dummy_scalar(pfirst:plast)
681 endif
682 else
683 do k=pfirst,plast
684 read(iunit,*,end=55,iostat=ierr1) dummy_scalar(k)
685 if (ierr1 /= 0) ierr = ierr1
686 enddo
687 endif
688 do k=pfirst,plast
689 dat(k,itemp,step) = dummy_scalar(k)
690 enddo
691 if (ierr /= 0) then
692 print*,' WARNING: errors reading temperatures'
693 ierr_out = -1
694 endif
695 case ("u")
696 ! Internal energy
697 pfirst = typedata(2,i); plast = typedata(3,i)
698 if (iambinaryfile>=1) then
699 if (doubleprec) then
700 read(iunit,end=55,iostat=ierr) dummy_dp_scalar(pfirst:plast)
701 dummy_scalar(pfirst:plast) = real(dummy_dp_scalar(pfirst:plast))
702 else
703 read(iunit,end=55,iostat=ierr) dummy_scalar(pfirst:plast)
704 endif
705 else
706 do k=pfirst,plast
707 read(iunit,*,end=55,iostat=ierr1) dummy_scalar(k)
708 if (ierr1 /= 0) ierr = ierr1
709 enddo
710 endif
711 do k=pfirst,plast
712 dat(k,iutherm,step) = dummy_scalar(k)
713 enddo
714 if (ierr /= 0) then
715 print*,' WARNING: errors reading internal energy'
716 ierr_out = -1
717 endif
718 case ("B")
719 ! Magnetic fields
720 if (doubleprec) allocate(dummy_dp(1:BDIMtemp,1:ptot),stat=ierr)
721 allocate(dummy(1:BDIMtemp,1:ptot),stat=ierr)
722 pfirst = typedata(2,i); plast = typedata(3,i)
723 if (iambinaryfile>=1) then
724 if (doubleprec) then
725 read(iunit,end=55,iostat=ierr) dummy_dp(1:BDIMtemp,pfirst:plast)
726 dummy(1:BDIMtemp,pfirst:plast) = real(dummy_dp(1:BDIMtemp,pfirst:plast))
727 else
728 read(iunit,end=55,iostat=ierr) dummy(1:BDIMtemp,pfirst:plast)
729 endif
730 else
731 do k=pfirst,plast
732 read(iunit,*,end=55,iostat=ierr1) dummy(1:BDIMtemp,k)
733 if (ierr1 /= 0) ierr = ierr1
734 enddo
735 endif
736 do k=pfirst,plast
737 dat(k,iBfirst:iBfirst+BDIMtemp-1,step) = dummy(1:BDIMtemp,k)
738 enddo
739 if (ierr /= 0) then
740 print*,' WARNING: errors reading magnetic fields'
741 ierr_out = -1
742 endif
743 deallocate(dummy)
744 if (doubleprec) deallocate(dummy_dp)
745 case ("sink_v1")
746 ! Load sinks in sink data storage, will add them later
747 pfirst = typedata(2,i); plast = typedata(3,i)
748 if (iambinaryfile>=1) then
749 read(iunit,end=55,iostat=ierr) nl,ni,nli,npr,ndp,nchar
750 else
751 read(iunit,fmt=*,end=55,iostat=ierr) nl,ni,nli,npr,ndp,nchar
752 endif
753 do s=pfirst,plast
754 if (iambinaryfile>=1) then
755 read(iunit,end=55,iostat=ierr) ldummy
756 read(iunit,end=55,iostat=ierr) idummy2
757 if (doubleprec) then
758 read(iunit,end=55,iostat=ierr) raux_dp
759 raux = real(raux_dp)
760 else
761 read(iunit,end=55,iostat=ierr) raux
762 endif
763 else
764 read(iunit,'(2L1)',end=55,iostat=ierr) ldummy
765 read(iunit,fmt=*,end=55,iostat=ierr) idummy2
766 read(iunit,sink_format_string) raux(1:sink_data_length)
767 endif
768 if (ix(1)/=0) sink_dat_array(s,ix(1):ix(NDIMtemp),1) = raux(2:NDIMtemp+1)
769 if (ivx/=0) sink_dat_array(s,ivx:ivx+VDIMtemp-1,1) = raux(NDIMtemp+2:NDIMtemp+VDIMtemp+1)
770 if (ipmass/=0) sink_dat_array(s,ipmass,1) = raux(NDIMtemp+VDIMtemp+2)
771 if (ih/=0) sink_dat_array(s,ih,1) = raux(NDIMtemp+VDIMtemp+3)
772 if (itemp/=0) sink_dat_array(s,itemp,1) = raux(NDIMtemp+VDIMtemp+11)
773 enddo
774 case default
775 !print*,' WARNING: unknown data type ', trim(data_id(i))
776 ! Assume this is an unknown data type
777 !ierr_out = -4
778 width = typedata(1,i)
779 pfirst = typedata(2,i); plast = typedata(3,i)
780 typecode = typedata(4,i); unit_id = typedata(5,i)
781 unknown = unknown + 1
782 if (typecode == 7) then
783 ! Special data structure we don't understand; read and skip
784 if (iambinaryfile>=1) then
785 read(iunit,end=55,iostat=ierr) nl,ni,nli,npr,ndp,nchar
786 else
787 read(iunit,fmt=*,end=55,iostat=ierr) nl,ni,nli,npr,ndp,nchar
788 endif
789 if (nchar > 0) stop "Fail! character data :("
790 if (nl > 0) allocate(l_data_st(1:nl))
791 if (ni > 0) allocate(i_data_st(1:ni))
792 if (nli > 0) allocate(ilp_data_st(1:nli))
793 if (npr > 0) then
794 allocate(sp_data_st(1:npr))
795 if (doubleprec) allocate(dp_data_st(1:npr))
796 endif
797 if (ndp > 0) allocate(dp_data_st2(1:ndp))
798 if (iambinaryfile>=1) then
799 do j=pfirst, plast
800 if (nl > 0) read(iunit,end=55,iostat=ierr) l_data_st
801 if (ni > 0) read(iunit,end=55,iostat=ierr) i_data_st
802 if (nli > 0) read(iunit,end=55,iostat=ierr) ilp_data_st
803 if (npr > 0) then
804 if (doubleprec) then
805 read(iunit,end=55,iostat=ierr) dp_data_st
806 else
807 read(iunit,end=55,iostat=ierr) sp_data_st
808 endif
809 endif
810 if (ndp > 0) read(iunit,end=55,iostat=ierr) dp_data_st2
811 enddo
812 else
813 do j=pfirst, plast
814 if (nl > 0) then
815 write (format_string,'(A,I0,A)') "(",nl,"L1)"
816 read(iunit,end=55,iostat=ierr,fmt=format_string) l_data_st
817 endif
818 if (ni > 0) then
819 read(iunit,end=55,iostat=ierr,fmt=*) i_data_st
820 endif
821 if (nli > 0) then
822 read(iunit,end=55,iostat=ierr,fmt=*) ilp_data_st
823 endif
824 if (npr > 0) then
825 if (doubleprec) then
826 read(iunit,end=55,iostat=ierr,fmt=*) dp_data_st
827 else
828 read(iunit,end=55,iostat=ierr,fmt=*) sp_data_st
829 endif
830 endif
831 if (ndp > 0) then
832 read(iunit,end=55,iostat=ierr,fmt=*) dp_data_st2
833 endif
834 enddo
835 endif
836 if (ierr /= 0) then
837 print*,' WARNING: errors reading unknown data structure ', trim(data_id(i))
838 ierr_out = -1
839 endif
840 if (allocated(i_data_st)) deallocate(i_data_st)
841 if (allocated(ilp_data_st)) deallocate(ilp_data_st)
842 if (allocated(sp_data_st)) deallocate(sp_data_st)
843 if (allocated(dp_data_st)) deallocate(dp_data_st)
844 if (allocated(dp_data_st2)) deallocate(dp_data_st2)
845 elseif (typecode == 6) then
846 ! Character data; read and skip
847 stop "Fail! character data :("
848 ! I have realised this was a silly idea
849 ! If we work out how this should work, I can put it in
850 elseif (typecode >= 1 .AND. typecode <= 5) then
851 ! 1 = logical, 2 = integer, 3 = long integer, 4 = PR, 5 = DP
852 ! Normal data set; either scalar or vector
853 if (width == 1) then
854 ! Scalar data
855 if (typecode==1) then
856 ! Logical data array
857 allocate(dummy_logical(1:ptot))
858 dummy_logical = .FALSE.
859 if (iambinaryfile>=1) then
860 read(iunit,end=55,iostat=ierr) dummy_logical(pfirst:plast)
861 else
862 do k=pfirst,plast
863 read(iunit,'(L1)',end=55,iostat=ierr1) dummy_logical(k)
864 if (ierr1 /= 0) ierr = ierr1
865 enddo
866 endif
867 where (dummy_logical)
868 dummy_scalar=1.d0
869 elsewhere
870 dummy_scalar=0.d0
871 end where
872 deallocate(dummy_logical)
873 elseif (typecode==2) then
874 ! Integer data array
875 dummy_int = 0
876 if (iambinaryfile>=1) then
877 read(iunit,end=55,iostat=ierr) dummy_int(pfirst:plast)
878 else
879 do k=pfirst,plast
880 read(iunit,*,end=55,iostat=ierr1) dummy_int(k)
881 if (ierr1 /= 0) ierr = ierr1
882 enddo
883 endif
884 dummy_scalar(pfirst:plast) = real(dummy_int(pfirst:plast))
885 elseif (typecode==3) then
886 ! Long integer data array
887 allocate(dummy_ilp_int(1:ptot))
888 dummy_ilp_int = 0
889 if (iambinaryfile>=1) then
890 read(iunit,end=55,iostat=ierr) dummy_ilp_int(pfirst:plast)
891 else
892 do k=pfirst,plast
893 read(iunit,*,end=55,iostat=ierr1) dummy_ilp_int(k)
894 if (ierr1 /= 0) ierr = ierr1
895 enddo
896 endif
897 dummy_scalar(pfirst:plast) = real(dummy_ilp_int(pfirst:plast))
898 deallocate(dummy_ilp_int)
899 elseif (typecode==4) then
900 ! PR data array
901 if (iambinaryfile>=1) then
902 if (doubleprec) then
903 read(iunit,end=55,iostat=ierr) dummy_dp_scalar(pfirst:plast)
904 dummy_scalar(pfirst:plast) = real(dummy_dp_scalar(pfirst:plast))
905 else
906 read(iunit,end=55,iostat=ierr) dummy_scalar(pfirst:plast)
907 endif
908 else
909 do k=pfirst,plast
910 read(iunit,*,end=55,iostat=ierr1) dummy_scalar(k)
911 if (ierr1 /= 0) ierr = ierr1
912 enddo
913 endif
914 elseif (typecode==5) then
915 ! DP data array
916 if (iambinaryfile>=1) then
917 if (.NOT.doubleprec) allocate(dummy_dp_scalar(pfirst:plast))
918 read(iunit,end=55,iostat=ierr) dummy_dp_scalar(pfirst:plast)
919 dummy_scalar(pfirst:plast) = real(dummy_dp_scalar(pfirst:plast))
920 if (.NOT.doubleprec) deallocate(dummy_dp_scalar)
921 else
922 do k=pfirst,plast
923 read(iunit,*,end=55,iostat=ierr1) dummy_scalar(k)
924 if (ierr1 /= 0) ierr = ierr1
925 enddo
926 endif
927 endif
928 do k=pfirst,plast
929 dat(k,iunknown(unknown),step) = dummy_scalar(k)
930 enddo
931 if (ierr /= 0) then
932 print*,' WARNING: errors reading unknown data type ', trim(data_id(i))
933 ierr_out = -1
934 endif
935 else
936 ! Vector data
937 allocate(dummy(1:width,1:ptot),stat=ierr)
938 if (typecode == 1) then
939 ! Logical data array
940 allocate(dummy_logical_2D(1:width,1:ptot))
941 dummy_logical_2D = .FALSE.
942 if (iambinaryfile>=1) then
943 read(iunit,end=55,iostat=ierr) dummy_logical_2D(1:width,pfirst:plast)
944 else
945 write (format_string,'(A,I0,A)') "(",width,"L1)"
946 do k=pfirst,plast
947 read(iunit,fmt=format_string,end=55,iostat=ierr1) dummy_logical_2D(1:width,k)
948 if (ierr1 /= 0) ierr = ierr1
949 enddo
950 endif
951 where (dummy_logical_2D)
952 dummy=1.d0
953 elsewhere
954 dummy=0.d0
955 end where
956 deallocate(dummy_logical_2D)
957 elseif (typecode == 2) then
958 ! Integer data array
959 allocate(dummy_int_2D(1:width,1:ptot))
960 dummy_int_2D = 0
961 if (iambinaryfile>=1) then
962 read(iunit,end=55,iostat=ierr) dummy_int_2D(1:width,pfirst:plast)
963 else
964 do k=pfirst,plast
965 read(iunit,*,end=55,iostat=ierr1) dummy_int_2D(1:width,k)
966 if (ierr1 /= 0) ierr = ierr1
967 enddo
968 endif
969 dummy(1:width,pfirst:plast) = real(dummy_int_2D(1:width,pfirst:plast))
970 deallocate(dummy_int_2D)
971 elseif (typecode == 3) then
972 ! Long integer data array
973 allocate(dummy_ilp_int_2D(1:width,1:ptot))
974 dummy_ilp_int_2D = 0
975 if (iambinaryfile>=1) then
976 read(iunit,end=55,iostat=ierr) dummy_ilp_int_2D(1:width,pfirst:plast)
977 else
978 do k=pfirst,plast
979 read(iunit,*,end=55,iostat=ierr1) dummy_ilp_int_2D(1:width,k)
980 if (ierr1 /= 0) ierr = ierr1
981 enddo
982 endif
983 dummy(1:width,pfirst:plast) = real(dummy_ilp_int_2D(1:width,pfirst:plast))
984 deallocate(dummy_ilp_int_2D)
985 elseif (typecode == 4) then
986 ! PR data array
987 if (doubleprec) allocate(dummy_dp(1:width,1:ptot),stat=ierr)
988 if (iambinaryfile>=1) then
989 if (doubleprec) then
990 read(iunit,end=55,iostat=ierr) dummy_dp(1:width,pfirst:plast)
991 dummy(1:width,pfirst:plast) = real(dummy_dp(1:width,pfirst:plast))
992 else
993 read(iunit,end=55,iostat=ierr) dummy(1:width,pfirst:plast)
994 endif
995 else
996 do k=pfirst,plast
997 read(iunit,*,end=55,iostat=ierr1) dummy(1:width,k)
998 if (ierr1 /= 0) ierr = ierr1
999 enddo
1000 endif
1001 if (doubleprec) deallocate(dummy_dp)
1002 elseif (typecode == 5) then
1003 ! DP data array
1004 if (iambinaryfile>=1) then
1005 allocate(dummy_dp(1:width,1:ptot),stat=ierr)
1006 read(iunit,end=55,iostat=ierr) dummy_dp(1:width,pfirst:plast)
1007 dummy(1:width,pfirst:plast) = real(dummy_dp(1:width,pfirst:plast))
1008 deallocate(dummy_dp)
1009 else
1010 do k=pfirst,plast
1011 read(iunit,*,end=55,iostat=ierr1) dummy(1:width,k)
1012 if (ierr1 /= 0) ierr = ierr1
1013 enddo
1014 endif
1015 endif
1016 do k=pfirst,plast
1017 dat(k,iunknown(unknown):iunknown(unknown)+width-1,step) = dummy(1:width,k)
1018 enddo
1019 if (ierr /= 0) then
1020 print*,' WARNING: errors reading unknown data type ', trim(data_id(i))
1021 ierr_out = -1
1022 endif
1023 deallocate(dummy)
1024 endif
1025 endif
1026
1027 end select
1028 enddo
1029 write (6,*)
1030
1031 if (stot>0) then
1032 ! Load sink stuff into end of dat array
1033 dat(ptot+1:ptot+stot,1:ncolumns,step) = sink_dat_array(1:stot,1:ncolumns,1)
1034 endif
1035
1036 return
1037
1038 55 continue
1039 if (iambinaryfile>=1) print "(a)",' ERROR: end of file in binary read'
1040 if (iambinaryfile==0) print "(a)",' ERROR: end of file in ascii read'
1041 ierr_out = -3
1042 return
1043
1044 56 continue
1045 ierr_out = -2
1046
1047 return
1048 end subroutine
1049
1050 !----------------------------------------------------
1051 ! translate types into order (for old dragon read)
1052 !----------------------------------------------------
1053 subroutine set_types(itypei,ntotal,noftype)
1054 integer(kind=int1), dimension(:), intent(inout) :: itypei
1055 integer, intent(in) :: ntotal
1056 integer, dimension(:), intent(out) :: noftype
1057 integer :: noftype_temp(1:7)
1058
1059 noftype = 0
1060
1061 noftype_temp(1) = pgas
1062 noftype_temp(2) = pboundary
1063 noftype_temp(3) = stot
1064 noftype_temp(4) = picm
1065 noftype_temp(5) = pcdm
1066 noftype_temp(6) = pdust
1067 noftype_temp(7) = pion
1068
1069 if (sum(noftype_temp(1:7)) /= ntotal) then
1070 print "(a)",' INTERNAL ERROR setting number in each type in dragon read'
1071 endif
1072
1073 do i=1,7
1074 if (i > seren_maxparttypes .AND. noftype_temp(i) > 0) then
1075 print*,' *** ERROR: not enough particle types for SEREN data read ***'
1076 print*,' *** you need to edit splash parameters and recompile ***'
1077 stop
1078 endif
1079 enddo
1080
1081 noftype(1:seren_maxparttypes) = noftype_temp(1:seren_maxparttypes)
1082
1083 if (pboundary>0) itypei(1:pboundary) = 2
1084 if (picm>0) itypei(pboundary+1:pboundary+picm) = 4
1085 if (pgas>0) itypei(pboundary+picm+1:pboundary+picm+pgas) = 1
1086 if (pcdm>0) itypei(pboundary+picm+pgas+1:pboundary+picm+pgas+pcdm) = 5
1087 if (pdust>0) itypei(pboundary+picm+pgas+pcdm+1:pboundary+picm+pgas+pcdm+pdust) = 6
1088 if (pion>0) itypei(pboundary+picm+pgas+pcdm+pdust+1:ptot) = 7
1089 if (stot>0) itypei(ptot+1:ptot+stot) = 3
1090
1091 return
1092 end subroutine set_types
1093
1094 end subroutine read_data_seren
1095
1096 !!------------------------------------------------------------
1097 !! set labels for each column of data
1098 !!------------------------------------------------------------
1099
1100 subroutine set_labels_seren
1101 use labels, only:label,iamvec,labelvec,labeltype,unitslabel=>unitslabel_default,&
1102 &ix,ivx,ipmass,ih,irho,iBfirst,iutherm,lenlabel,lenunitslabel,make_vector_label
1103 use params
1104 use settings_data, only:ndim,ndimV,ncolumns,ntypes,UseTypeInRenderings
1105 use geometry, only:labelcoord
1106 use settings_units, only:units=>units_default
1107 use seren_data_store
1108 integer :: i, j, width, unit_no
1109 integer :: nunknown ! Number of unknown data types
1110 character(len=lenunitslabel) :: unit_base, unit_string
1111 character(len=lenlabel) :: type_names(1:7)
1112 logical :: type_use_render(1:7)
1113
1114 if (ndim <= 0 .or. ndim > 3) then
1115 print*,'*** ERROR: ndim = ',ndim,' in set_labels_seren ***'
1116 return
1117 endif
1118 if (ndimV <= 0 .or. ndimV > 3) then
1119 print*,'*** ERROR: ndimV = ',ndimV,' in set_labels_seren ***'
1120 return
1121 endif
1122
1123 ! Calculate number of columns to read
1124 iporig = 0
1125 ncolumns = 0
1126 nunknown = 0
1127 do i=1,ndata
1128 unit_no = typedata(5,i)
1129 !write (6,*) "i = ", i, "; data_id(i) = ", data_id(i)
1130 unit_base = ""
1131 unit_string = ""
1132 if (unit_no < 0 .OR. unit_no > nunits) then
1133 print*,'*** ERROR: unit_no = ',unit_no,' in set_labels_seren ***'
1134 elseif (unit_no /= 0) then
1135 unit_base = trim(adjustl(unit_data(unit_no)))
1136 unit_string = unit_base
1137 call translate_unit_names(unit_string)
1138 unit_string = ' ['//trim(adjustl(unit_string))//']'
1139 endif
1140 !write (6,*) "unit_base, unit_string = ", unit_base, unit_string
1141 select case (trim(data_id(i)))
1142 case ("porig")
1143 ! Original particle number
1144 iporig = -1 ! We always want this last
1145 case ("r")
1146 ! Position
1147 do j=1,NDIMtemp
1148 ix(j) = ncolumns + j
1149 units(ix(j)) = unit_coeff(ix(j))
1150 unitslabel(ix(j)) = unit_string
1151 enddo
1152 ! unitzintegration = units(ix(1))
1153 ! labelzintegration = ' ['//trim(adjustl(unit_string))//']'
1154 label(ix(1:ndim)) = labelcoord(1:ndim,1)
1155 ncolumns = ncolumns + NDIMtemp
1156 r_unit = trim(adjustl(unit_base))
1157 case ("h")
1158 ! Smoothing lengths
1159 ih = ncolumns + 1
1160 units(ih) = unit_coeff(ih)
1161 unitslabel(ih) = unit_string
1162 label(ih) = 'h'
1163 ncolumns = ncolumns + 1
1164 h_unit = trim(adjustl(unit_base))
1165 case ("m")
1166 ! Mass
1167 ipmass = ncolumns + 1
1168 units(ipmass) = unit_coeff(ipmass)
1169 unitslabel(ipmass) = unit_string
1170 label(ipmass) = 'particle mass'
1171 ncolumns = ncolumns + 1
1172 m_unit = trim(adjustl(unit_base))
1173 case ("v")
1174 ! Velocities
1175 ivx = ncolumns + 1
1176 call make_vector_label('v',ivx,VDIMtemp,iamvec,labelvec,label,labelcoord(:,1))
1177 do j=1,VDIMtemp
1178 units(ivx+j-1) = unit_coeff(ivx+j-1)
1179 unitslabel(ivx+j-1) = unit_string
1180 enddo
1181 ncolumns = ncolumns + VDIMtemp
1182 case ("rho")
1183 ! Densities
1184 irho = ncolumns + 1
1185 units(irho) = unit_coeff(irho)
1186 unitslabel(irho) = unit_string
1187 label(irho) = 'density'
1188 ncolumns = ncolumns + 1
1189 rho_unit = trim(adjustl(unit_base))
1190 case ("temp")
1191 ! Temperatures
1192 itemp = ncolumns + 1 ! NOT A PROPER SPLASH i_quantity
1193 units(itemp) = unit_coeff(itemp)
1194 unitslabel(itemp) = unit_string
1195 label(ncolumns + 1) = 'temperature'
1196 ncolumns = ncolumns + 1
1197 case ("u")
1198 ! Internal energy
1199 iutherm = ncolumns + 1
1200 units(iutherm) = unit_coeff(iutherm)
1201 unitslabel(iutherm) = unit_string
1202 label(ncolumns + 1) = 'internal energy'
1203 ncolumns = ncolumns + 1
1204 case ("B")
1205 ! Magnetic fields
1206 iBfirst = ncolumns + 1
1207 call make_vector_label('B',iBfirst,BDIMtemp,iamvec,labelvec,label,labelcoord(:,1))
1208 do j=1,BDIMtemp
1209 units(iBfirst+j-1) = unit_coeff(iBfirst+j-1)
1210 unitslabel(iBfirst+j-1) = unit_string
1211 enddo
1212 ncolumns = ncolumns + BDIMtemp
1213 case ("sink_v0")
1214 ! Do nothing yet, sinks are stored separately
1215 case ("sink_v1")
1216 ! Do nothing yet, sinks are stored separately
1217 case default
1218 print*,' WARNING reading file: unknown data type ', trim(data_id(i))
1219 if (typedata(4,i) == 7) cycle ! Special data module we don't understand; ignore
1220 if (typedata(4,i) == 6) cycle ! Not a lot we can do with character data here!
1221 width = typedata(1,i)
1222 nunknown = nunknown + 1
1223 iunknown(nunknown) = ncolumns + 1 ! NOT A PROPER SPLASH i_quantity
1224 if (width == 1) then
1225 label(iunknown(nunknown)) = trim(data_id(i))
1226 units(iunknown(nunknown)) = unit_coeff(iunknown(nunknown))
1227 unitslabel(iunknown(nunknown)) = unit_string
1228 elseif (width <= NDIMtemp) then
1229 do j=1,width
1230 label(iunknown(nunknown)+j-1) = trim(data_id(i))//'\d'//labelcoord(j,1)
1231 units(iunknown(nunknown)+j-1) = unit_coeff(iunknown(nunknown))
1232 unitslabel(iunknown(nunknown)+j-1) = unit_string
1233 enddo
1234 else
1235 do j=1,width
1236 write(label(iunknown(nunknown)+j-1),'(A,A,I0)') trim(data_id(i)),'\d',j
1237 units(iunknown(nunknown)+j-1) = unit_coeff(iunknown(nunknown))
1238 unitslabel(iunknown(nunknown)+j-1) = unit_string
1239 enddo
1240 endif
1241 ncolumns = ncolumns + width ! Add width of data to ncolumns
1242 end select
1243 enddo
1244 if (iporig == -1) then
1245 ! If there is porig, add as last column
1246 iporig = ncolumns + 1 ! NOT A PROPER SPLASH i_quantity
1247 label(ncolumns + 1) = 'particle id'
1248 ncolumns = ncolumns + 1
1249 endif
1250
1251 !--set labels for each particle type
1252 !
1253 ntypes = seren_maxparttypes
1254 type_names = (/'gas ','boundary','sink ','icm ','cdm ','dust ','ion '/)
1255 type_use_render = (/.TRUE.,.TRUE.,.FALSE.,.TRUE.,.TRUE.,.TRUE.,.TRUE./)
1256
1257 labeltype(1:ntypes) = type_names(1:ntypes)
1258 UseTypeInRenderings(1:ntypes) = type_use_render(1:ntypes)
1259
1260 end subroutine set_labels_seren
1261
1262 subroutine find_weights(out_unit_interp,out_unitzintegration,out_labelzintegration)
1263 use labels, only:lenunitslabel
1264 use params
1265 use seren_data_store
1266
1267 real(doub_prec), intent(out) :: out_unit_interp
1268 real, intent(out) :: out_unitzintegration
1269 character(len=lenunitslabel), intent(out) :: out_labelzintegration
1270 real(doub_prec) :: dm_unit, dh_unit, drho_unit, dr_unit
1271 logical :: do_dimweight, do_zintegration
1272 character(len=lenunitslabel) :: rho_length_label
1273 real(doub_prec) :: rho_length
1274
1275 out_unit_interp = 1.0
1276 out_unitzintegration = 1.0
1277 out_labelzintegration = ""
1278
1279 do_dimweight = .TRUE.
1280 do_zintegration = .TRUE.
1281
1282 if (m_unit=="") then
1283 print*,'No masses or no mass units!'
1284 print*,'Cannot create dimensionless weight (unnormalised rendered plots may be incorrect)'
1285 do_dimweight = .FALSE.
1286 endif
1287 if (h_unit=="") then
1288 print*,'No smoothing lengths or no smoothing length units!'
1289 print*,'Cannot create dimensionless weight (unnormalised rendered plots may be incorrect)'
1290 do_dimweight = .FALSE.
1291 endif
1292 if (rho_unit=="") then
1293 print*,'No densities or no density units!'
1294 print*,'Cannot create dimensionless weight (unnormalised rendered plots may be incorrect)'
1295 do_dimweight = .FALSE.
1296 print*,'Cannot set unitzintegration (column density plots may be incorrect)'
1297 do_zintegration = .FALSE.
1298 endif
1299 if (r_unit=="") then
1300 print*,'No positions or no position units!'
1301 print*,'Cannot set unitzintegration (column density plots may be incorrect)'
1302 do_zintegration = .FALSE.
1303 endif
1304
1305
1306 ! Length unit in S.I. units (m)
1307 if (r_unit=="pc") then
1308 dr_unit = r_pc
1309 elseif (r_unit=="au") then
1310 dr_unit = r_au
1311 elseif (r_unit=="r_sun") then
1312 dr_unit = r_sun
1313 elseif (r_unit=="r_earth") then
1314 dr_unit = r_earth
1315 elseif (r_unit=="km") then
1316 dr_unit = 1000.0_DP
1317 elseif (r_unit=="m") then
1318 dr_unit = 1.0_DP
1319 elseif (r_unit=="cm") then
1320 dr_unit = 0.01_DP
1321 else
1322 print*,'Unknown position unit ', r_unit, '!'
1323 print*,'Cannot set unitzintegration (column density plots may be incorrect)'
1324 do_zintegration = .FALSE.
1325 dr_unit = 1.0_DP
1326 endif
1327
1328 ! Length unit in S.I. units (m)
1329 if (h_unit=="pc") then
1330 dh_unit = r_pc
1331 elseif (h_unit=="au") then
1332 dh_unit = r_au
1333 elseif (h_unit=="r_sun") then
1334 dh_unit = r_sun
1335 elseif (h_unit=="r_earth") then
1336 dh_unit = r_earth
1337 elseif (h_unit=="km") then
1338 dh_unit = 1000.0_DP
1339 elseif (h_unit=="m") then
1340 dh_unit = 1.0_DP
1341 elseif (h_unit=="cm") then
1342 dh_unit = 0.01_DP
1343 else
1344 print*,'Unknown smoothing length unit ', h_unit, '!'
1345 print*,'Cannot create dimensionless weight (unnormalised rendered plots may be incorrect)'
1346 do_dimweight = .FALSE.
1347 dh_unit = 1.0_DP
1348 endif
1349
1350 ! Mass units in S.I. units (kg)
1351 if (m_unit=="m_sun") then
1352 dm_unit = m_sun
1353 elseif (m_unit=="m_jup") then
1354 dm_unit = m_jup
1355 elseif (m_unit=="m_earth") then
1356 dm_unit = m_earth
1357 elseif (m_unit=="kg") then
1358 dm_unit = 1._DP
1359 elseif (m_unit=="g") then
1360 dm_unit = 1.0E-3_DP
1361 else
1362 print*,'Unknown mass unit ', m_unit, '!'
1363 print*,'Cannot create dimensionless weight (unnormalised rendered plots may be incorrect)'
1364 do_dimweight = .FALSE.
1365 dm_unit = 1._DP
1366 endif
1367
1368 ! Density units in S.I. units (i.e. kg/m^3)
1369 if (rho_unit=="m_sun_pc3") then
1370 drho_unit = m_sun / (r_pc**3)
1371 rho_length = r_pc
1372 rho_length_label = "pc"
1373 elseif (rho_unit=="m_sun_pc2") then
1374 drho_unit = m_sun / (r_pc**2)
1375 rho_length = r_pc
1376 rho_length_label = "pc"
1377 elseif (rho_unit=="kg_m3") then
1378 drho_unit = 1.0_DP
1379 rho_length = 1.0_DP
1380 rho_length_label = "m"
1381 elseif (rho_unit=="kg_m2") then
1382 drho_unit = 1.0_DP
1383 rho_length = 1.0_DP
1384 rho_length_label = "m"
1385 elseif (rho_unit=="g_cm3") then
1386 drho_unit = 1.0E3_DP
1387 rho_length = 0.01_DP
1388 rho_length_label = "cm"
1389 elseif (rho_unit=="g_cm2") then
1390 drho_unit = 10.0_DP
1391 rho_length = 0.01_DP
1392 rho_length_label = "cm"
1393 else
1394 print*,'Unknown density unit ', rho_unit, '!'
1395 print*,'Cannot create dimensionless weight (unnormalised rendered plots may be incorrect)'
1396 do_dimweight = .FALSE.
1397 print*,'Cannot set unitzintegration (column density plots may be incorrect)'
1398 do_zintegration = .FALSE.
1399 rho_length = 1.0_DP
1400 endif
1401
1402 if (do_dimweight) then
1403 out_unit_interp = dm_unit/(drho_unit*dh_unit**NDIMtemp)
1404 endif
1405
1406 if (do_zintegration) then
1407 out_unitzintegration = dr_unit / rho_length
1408 out_labelzintegration = rho_length_label
1409 endif
1410
1411 return
1412 end subroutine find_weights
1413
1414 subroutine translate_unit_names(unit_name)
1415 character(len=*), intent(inout) :: unit_name
1416
1417 select case (trim(unit_name))
1418 case ("r_sun")
1419 unit_name = "r_{Sun}"
1420 case ("au")
1421 unit_name = "AU"
1422 case ("r_earth")
1423 unit_name = "r_{Earth}"
1424 case ("m_sun")
1425 unit_name = "M_{\(2281)}"
1426 case ("m_jup")
1427 unit_name = "M_{Jupiter}"
1428 case ("m_earth")
1429 unit_name = "M_{Earth}"
1430 case ("myr")
1431 unit_name = "Myrs"
1432 case ("km_s")
1433 unit_name = "km s^{-1}"
1434 case ("au_yr")
1435 unit_name = "AU / yr"
1436 case ("m_s")
1437 unit_name = "m s^{-1}"
1438 case ("cm_s")
1439 unit_name = "cm s^{-1}"
1440 case ("km_s2")
1441 unit_name = "km s^{-2}"
1442 case ("au_yr2")
1443 unit_name = "AU yr^{-2}"
1444 case ("m_s2")
1445 unit_name = "m s^{-2}"
1446 case ("cm_s2")
1447 unit_name = "cm s^{-2}"
1448 case ("m_sun_pc3")
1449 unit_name = "M_{\(2281)} pc^{-3}"
1450 case ("kg_m_3")
1451 unit_name = "kg m^{-3}"
1452 case ("g_cm_3")
1453 unit_name = "g cm^{-3}"
1454 case ("m_sun_pc2")
1455 unit_name = "M_{\(2281)} pc^{-2}"
1456 case ("kg_m_2")
1457 unit_name = "kg m^{-2}"
1458 case ("g_cm_2")
1459 unit_name = "g cm^{-2}"
1460 case ("g_cms2")
1461 unit_name = "g cm^{-2}"
1462 case ("10^40erg")
1463 unit_name = "\x 10^{40} ergs"
1464 case ("m_sunkm_s")
1465 unit_name = "M_{\(2281)} km s^{-1}"
1466 case ("m_sunau_yr")
1467 unit_name = "M_{\(2281)} AU yr^{-1}"
1468 case ("kgm_s")
1469 unit_name = "kg m s^{-1}"
1470 case ("gcm_s")
1471 unit_name = "g cm s^{-1}"
1472 case ("m_sunkm2_s")
1473 unit_name = "M_{\(2281)} km^{2} s^{-1}"
1474 case ("m_sunau2_yr")
1475 unit_name = "M_{\(2281)} AU^{2} yr^{-1}"
1476 case ("kgm2_s")
1477 unit_name = "kg m^{2} s^{-1}"
1478 case ("gcm2_s")
1479 unit_name = "g cm^{2} s^{-1}"
1480 case ("rad_s")
1481 unit_name = "radians s^{-1}"
1482 case ("m_sun_myr")
1483 unit_name = "M_{\(2281)} Myr^{-1}"
1484 case ("m_sun_yr")
1485 unit_name = "M_{\(2281)} yr^{-1}"
1486 case ("kg_s")
1487 unit_name = "kg s^{-1}"
1488 case ("g_s")
1489 unit_name = "g s^{-1}"
1490 case ("L_sun")
1491 unit_name = "L_{\(2281)}"
1492 case ("J_s")
1493 unit_name = "J s^{-1}"
1494 case ("ergs_s")
1495 unit_name = "ergs s^{-1}"
1496 case ("m2_kg")
1497 unit_name = "m^{2} kg^{-1}"
1498 case ("cm2_g")
1499 unit_name = "cm^{2} g^{-1}"
1500 case ("tesla")
1501 unit_name = "Tesla"
1502 case ("gauss")
1503 unit_name = "Gauss"
1504 case ("C_s_m2")
1505 unit_name = "C s^{-1} m^{-2}"
1506 case ("J_kg")
1507 unit_name = "J kg^{-1}"
1508 case ("erg_g")
1509 unit_name = "ergs g^{-1}"
1510 case default
1511 unit_name = unit_name ! this could be improved
1512 end select
1513
1514 return
1515 end subroutine translate_unit_names
1516 end module readdata_seren