Debian Codegraph @

src/read_data_dragon.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-2011 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 DRAGON 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 unit_constants
58 integer, parameter :: DP = selected_real_kind(p=15) ! double precision
59
60 ! Length units in metres
61 real(kind=DP),parameter :: r_pc = 3.08568E16_DP ! parsec
62 real(kind=DP),parameter :: r_au = 1.49597870E11_DP ! astronomical unit
63 real(kind=DP),parameter :: r_sun = 6.96E8_DP ! solar radius
64 real(kind=DP),parameter :: r_earth = 6.371E6_DP ! Earth radius
65
66 ! Mass units in kilograms
67 real(kind=DP),parameter :: m_sun = 1.98892E30_DP ! solar mass
68 real(kind=DP),parameter :: m_jup = 1.8986E27_DP ! Jupiter mass
69 real(kind=DP),parameter :: m_earth = 5.9736E24_DP ! Earth mass
70
71 ! Time units in seconds
72 real(kind=DP),parameter :: myr = 3.1556952E13_DP ! megayear
73 real(kind=DP),parameter :: yr = 3.1556952E7_DP ! year
74 real(kind=DP),parameter :: day = 8.64E4_DP ! day
75
76 end module unit_constants
77
78 module readdata_dragon
79 implicit none
80
81 public :: read_data_dragon, set_labels_dragon
82
83 private
84 contains
85
86 subroutine read_data_dragon(rootname,istepstart,ipos,nstepsread)
87 use particle_data, only:dat,iamtype,npartoftype,time,gamma,maxpart,maxcol,maxstep
88 use params
89 use settings_data, only:ndim,ndimV,ncolumns,ncalc,required,ipartialread,ntypes
90 use settings_units, only:unitzintegration, unit_interp
91 use mem_allocation, only:alloc
92 use labels, only:label,labeltype,labelzintegration
93 use system_utils, only:ienvironment
94 integer, intent(in) :: istepstart,ipos
95 integer, intent(out) :: nstepsread
96 character(len=*), intent(in) :: rootname
97 character(len=len(rootname)+10) :: datfile
98 integer, parameter :: iunit = 16
99 integer :: i,j,icol,ierr,iambinaryfile,itype
100 integer :: ncolstep,npart_max,nstep_max,ntoti,nlastcol,nextracols
101 logical :: iexist,reallocate,doubleprec
102 character(len=11) :: fmt
103 character(len=50) :: string
104
105 integer :: nei_want,nei_min,nmax
106 integer, dimension(:), allocatable :: iparttype
107 integer, dimension(20) :: idata
108 real, dimension(50) :: rdata
109 real(doub_prec), dimension(50) :: rdatadb
110 real :: timetemp,gammatemp,runit,massunit,sinksoft,sinkrad
111
112 nstepsread = 0
113 if (len_trim(rootname) > 0) then
114 datfile = trim(rootname)
115 else
116 print*,' **** no data read **** '
117 return
118 endif
119 !
120 !--check if first data file exists
121 !
122 inquire(file=datfile,exist=iexist)
123 if (.not.iexist) then
124 print "(a)",' *** error: '//trim(datfile)//': file not found ***'
125 return
126 endif
127 !
128 !--set parameters which do not vary between timesteps
129 !
130 ndim = 3
131 ndimV = 3
132 ncolstep = ndim + ndimV + 4 ! pos x 3, vel x 3, temp, h, rho, mass
133 nlastcol = ncolstep
134 nextracols = ienvironment('DSPLASH_EXTRACOLS',0)
135 if (nextracols > 0 .and. nextracols <= 99) then
136 print "(a,i2,a)",' ASSUMING ',nextracols,' EXTRA COLUMNS BEYOND ITYPE'
137 ncolstep = ncolstep + nextracols
138 else
139 nextracols = 0
140 endif
141 ncolumns = ncolstep
142 call set_labels_dragon
143 !
144 !--read data from snapshots
145 !
146 j = istepstart
147
148 write(*,"(23('-'),1x,a,1x,23('-'))") trim(datfile)
149 !
150 !--open data file and read data
151 !
152 !
153 !--determine whether file is binary or ascii, open it and read the header
154 !
155 inquire(file=datfile,form=fmt)
156 !print*,'fmt = ',fmt
157
158 ! select case(trim(adjustl(fmt)))
159 ! case('UNFORMATTED')
160 ! iambinaryfile = 1
161 ! open(unit=iunit,file=datfile,status='old',form='unformatted',iostat=ierr)
162 ! write (6,*) "Compiler identified as UNFORMATTED"
163 ! case('FORMATTED')
164 ! iambinaryfile = 0
165 ! open(unit=iunit,file=datfile,status='old',form='formatted',iostat=ierr)
166 ! write (6,*) "Compiler identified as FORMATTED"
167 ! case default
168 !--if compiler cannot distinguish the two, try binary first, then ascii
169 iambinaryfile = -1
170 open(unit=iunit,file=datfile,status='old',form='unformatted',iostat=ierr)
171 ! end select
172
173 if (ierr /= 0) then
174 print "(a)",'*** ERROR OPENING '//trim(datfile)//' ***'
175 return
176 endif
177 !
178 !--read the file header
179 ! try binary format first, and if unsuccessful try ascii
180 !
181 doubleprec = .true.
182 if (iambinaryfile==1) then
183 print "(a)",' reading binary dragon format '
184 call read_dragonheader_binary(iunit,ierr)
185 elseif (iambinaryfile==0) then
186 print "(a)",' reading ascii dragon format '
187 call read_dragonheader_ascii(iunit,ierr,iambinaryfile)
188 else
189 call read_dragonheader_binary(iunit,ierr)
190 if (ierr==0) then
191 !--if successful binary header read, file is doubleprec binary
192 iambinaryfile = 1
193 print "(a)",' reading binary dragon format '
194 print "(a)",' Double precision file'
195 else
196 !--otherwise, close binary file, and assume file is single precision binary
197 doubleprec = .false.
198 close(unit=iunit)
199 iambinaryfile = 1
200 open(unit=iunit,file=datfile,status='old',form='unformatted',iostat=ierr)
201 call read_dragonheader_binary(iunit,ierr)
202 if (ierr==0) then
203 print "(a)",' reading binary dragon format '
204 print "(a)",' Single precision file'
205 else
206 print "(a)",' reading ascii dragon format '
207 iambinaryfile = 0
208 close(unit=iunit)
209 open(unit=iunit,file=datfile,status='old',form='formatted',iostat=ierr)
210 call read_dragonheader_ascii(iunit,ierr,iambinaryfile)
211 if (ierr/=0) then
212 print "(a)",' ERROR reading ascii file header: wrong endian binary? '
213 close (iunit)
214 ndim = 0
215 ncolumns = 0
216 return
217 endif
218 endif
219 endif
220 endif
221 !
222 !--get values of quantities from the header
223 !
224 ntoti = idata(1)
225 nmax = idata(3)
226 nei_want = idata(10)
227 nei_min = idata(12)
228
229 !--check for errors in integer header (either from corrupt file or wrong endian)
230 if (ntoti <= 0 .or. ntoti > 1.e10 .or. nmax < 0 &
231 .or. nei_want < 0 .or. nei_want > 1e6 .or. nei_min < 0) then
232 if (iambinaryfile==1) then
233 print "(a)",' ERROR reading binary file header: wrong endian? '
234 else
235 print "(a)",' ERROR reading ascii file header '
236 endif
237 ndim = 0
238 ncolumns = 0
239 close(unit=iunit)
240 return
241 endif
242
243 if (doubleprec) then
244 timetemp = rdatadb(1)
245 runit = rdatadb(21)
246 massunit = rdatadb(22)
247 gammatemp = rdatadb(26)
248 sinksoft = rdatadb(27)
249 sinkrad = rdatadb(38)
250 else
251 timetemp = rdata(1)
252 runit = rdata(21)
253 massunit = rdata(22)
254 gammatemp = rdata(26)
255 sinksoft = rdata(27)
256 sinkrad = rdata(38)
257 endif
258
259 !--assume first that the file is single precision, check values are sensible, if not try double
260 ! if (iambinaryfile==1) then
261 ! if (timetemp < 0. .or. runit < 0. .or. massunit < 0. .or. gammatemp < 0. &
262 ! .or. gammatemp > 6.) then
263 ! print "(a)",' double precision file'
264 ! doubleprec = .true.
265 ! rewind(iunit)
266 ! call read_dragonheader_binary(iunit,ierr)
267 ! else
268 ! print "(a)",' single precision file'
269 ! endif
270 ! endif
271
272 print*,'time : ',timetemp
273 print*,'gamma : ',gammatemp
274 print*,'n_total : ',ntoti
275
276 if (ierr /= 0) then
277 if (iambinaryfile==1) then
278 print "(a)",' ERROR reading real part of binary file header '
279 else
280 print "(a)",' ERROR reading real part of ascii file header '
281 endif
282 ndim = 0
283 ncolumns = 0
284 close(unit=iunit)
285 return
286 endif
287 !
288 !--if successfully read header, increment the nstepsread counter
289 !
290 nstepsread = nstepsread + 1
291 !
292 !-- now work out dimensionless weight unit and z integration unit
293 !
294 call find_weights(unit_interp,unitzintegration,labelzintegration)
295 !
296 !--now read data
297 !
298 reallocate = .false.
299 npart_max = maxpart
300 nstep_max = max(maxstep,1)
301
302 if (ntoti > maxpart) then
303 reallocate = .true.
304 if (maxpart > 0) then
305 ! if we are reallocating, try not to do it again
306 npart_max = int(1.1*ntoti)
307 else
308 ! if first time, save on memory
309 npart_max = int(ntoti)
310 endif
311 endif
312 if (j >= maxstep .and. j /= 1) then
313 nstep_max = j + max(10,INT(0.1*nstep_max))
314 reallocate = .true.
315 endif
316 !
317 !--reallocate memory for main data array
318 !
319 if (reallocate .or. .not.(allocated(dat))) then
320 call alloc(npart_max,nstep_max,max(ncolstep+ncalc,maxcol),mixedtypes=.true.)
321 endif
322 !
323 !--copy header into header arrays
324 !
325 npartoftype(:,j) = 0
326 npartoftype(1,j) = ntoti
327 time(j) = timetemp
328 gamma(j) = gammatemp
329 !
330 !--read particle data
331 !
332 if (ntoti > 0) then
333 if (iambinaryfile==1) then
334 call read_dragonbody_binary(iunit,ierr)
335 else
336 call read_dragonbody_ascii(iunit,ierr)
337 endif
338 else
339 ntoti = 0
340 npartoftype(1,i) = 0
341 dat(:,:,i) = 0.
342 endif
343
344 if (allocated(iamtype)) then
345 !--relabel particle types
346 call set_types(iamtype(:,j),ntoti,npartoftype(:,j))
347 endif
348 if (any(npartoftype(2:,j) /= 0)) then
349 do itype=1,ntypes
350 if (npartoftype(itype,j) > 0) then
351 string = ' '
352 write(string,"(a)") 'n_'//trim(labeltype(itype))
353 write(string(18:len(string)),"(a)") ':'
354 print*,trim(string),' ',npartoftype(itype,j)
355 endif
356 enddo
357 endif
358 !
359 !--set flag to indicate that only part of this file has been read
360 !
361 if (.not.all(required(1:ncolstep))) ipartialread = .true.
362 !
363 !--close data file and return
364 !
365 if (allocated(iparttype)) deallocate(iparttype)
366 close(unit=iunit)
367
368 return
369
370 contains
371
372 !----------------------------------------------------
373 ! binary header read
374 !----------------------------------------------------
375 subroutine read_dragonheader_binary(iunitb,ierr)
376 integer, intent(in) :: iunitb
377 integer, intent(out) :: ierr
378
379 read(iunitb,end=55,iostat=ierr) idata
380 if (doubleprec) then
381 read(iunitb,end=55,iostat=ierr) rdatadb
382 else
383 read(iunitb,end=55,iostat=ierr) rdata
384 endif
385
386 return
387
388 55 continue
389 !print "(a)",' ERROR: end of file in binary header read'
390 ierr = -1
391 return
392
393 end subroutine read_dragonheader_binary
394
395 !----------------------------------------------------
396 ! ascii header read
397 !----------------------------------------------------
398 subroutine read_dragonheader_ascii(iunita,ierr,iwarn)
399 integer, intent(in) :: iunita,iwarn
400 integer, intent(out) :: ierr
401
402 do i=1,size(idata)
403 read(iunita,*,end=55,iostat=ierr) idata(i)
404 enddo
405
406 do i=1,size(rdata)
407 read(iunita,*,end=55,iostat=ierr) rdata(i)
408 enddo
409 doubleprec = .false.
410 return
411
412 55 continue
413 if (iwarn >= 0) print "(a)",' ERROR: end of file in binary header read'
414 ierr = -1
415 return
416
417 end subroutine read_dragonheader_ascii
418
419 !----------------------------------------------------
420 ! binary body read
421 !----------------------------------------------------
422 subroutine read_dragonbody_binary(iunitb,ierr)
423 integer, intent(in) :: iunitb
424 integer, intent(out) :: ierr
425 real(doub_prec), dimension(:,:), allocatable :: dummyx
426 real(doub_prec), dimension(:), allocatable :: dummy
427 integer, dimension(:), allocatable :: idumtype
428 integer :: icol
429
430 if (doubleprec .and. any(required(1:ndim+ndimV))) then
431 allocate(dummyx(3,ntoti),stat=ierr)
432 if (ierr /= 0) then
433 print *,' ERROR allocating memory'
434 goto 56
435 endif
436 endif
437
438 !--positions
439 if (any(required(1:ndim))) then
440 if (doubleprec) then
441 read(iunitb,end=55,iostat=ierr) dummyx(1:ndim,1:ntoti)
442 do i=1,ntoti
443 dat(i,1:ndim,j) = real(dummyx(1:ndim,i))
444 enddo
445 else
446 read(iunitb,end=55,iostat=ierr) (dat(i,1:ndim,j),i=1,ntoti)
447 endif
448 if (ierr /= 0) print*,' WARNING: errors reading positions '
449 else
450 read(iunitb,end=55,iostat=ierr)
451 if (ierr /= 0) print*,' WARNING: error skipping positions '
452 endif
453
454 !--velocities
455 if (any(required(ndim+1:ndim+ndimV))) then
456 if (doubleprec) then
457 read(iunitb,end=55,iostat=ierr) dummyx(1:ndimV,1:ntoti)
458 do i=1,ntoti
459 dat(i,ndim+1:ndim+ndimV,j) = real(dummyx(1:ndimV,i))
460 enddo
461 else
462 read(iunitb,end=55,iostat=ierr) (dat(i,ndim+1:ndim+ndimV,j),i=1,ntoti)
463 endif
464 if (ierr /= 0) print*,' WARNING: errors reading velocities '
465 else
466 read(iunitb,end=55,iostat=ierr)
467 if (ierr /= 0) print*,' WARNING: error skipping velocities '
468 endif
469
470 if (doubleprec .and. any(required(ndim+ndimV+1:ncolstep))) then
471 allocate(dummy(ntoti),stat=ierr)
472 if (ierr /= 0) then
473 print*,' ERROR allocating memory'
474 goto 56
475 endif
476 endif
477
478 !--the rest
479 do icol = ndim+ndimV+1,nlastcol
480 if (required(icol)) then
481 if (doubleprec) then
482 read(iunitb,end=55,iostat=ierr) dummy(1:ntoti)
483 dat(1:ntoti,icol,j) = real(dummy(1:ntoti))
484 else
485 read(iunitb,end=55,iostat=ierr) dat(1:ntoti,icol,j)
486 endif
487 if (ierr /= 0) print*,' WARNING: errors reading '//trim(label(icol))
488 else
489 read(iunitb,end=55,iostat=ierr)
490 if (ierr /= 0) print*,' WARNING: error skipping '//trim(label(icol))
491 endif
492 enddo
493
494 if (size(iamtype(:,j)) > 1) then
495 allocate(idumtype(ntoti),stat=ierr)
496 if (ierr /= 0) then
497 print*,'error reading type, assuming all gas'
498 iamtype(1:ntoti,j) = 1
499 else
500 read(iunitb,end=55,iostat=ierr) idumtype(1:ntoti)
501 iamtype(1:ntoti,j) = idumtype(1:ntoti)
502 endif
503 deallocate(idumtype)
504 if (ierr /= 0) print*,' WARNING: error reading itype'
505 endif
506
507 !--extra columns beyond itype
508 do icol = nlastcol+1,nlastcol+nextracols
509 if (required(icol)) then
510 if (doubleprec) then
511 read(iunitb,end=55,iostat=ierr) dummy(1:ntoti)
512 dat(1:ntoti,icol,j) = real(dummy(1:ntoti))
513 else
514 read(iunitb,end=55,iostat=ierr) dat(1:ntoti,icol,j)
515 endif
516 if (ierr /= 0) print*,' WARNING: errors reading '//trim(label(icol))
517 else
518 read(iunitb,end=55,iostat=ierr)
519 if (ierr /= 0) print*,' WARNING: error skipping '//trim(label(icol))
520 endif
521 enddo
522
523 if (allocated(dummyx)) deallocate(dummyx)
524 if (allocated(dummy)) deallocate(dummy)
525 return
526
527 55 continue
528 print "(a)",' ERROR: end of file in binary read'
529 56 continue
530 ierr = -1
531
532 if (allocated(dummyx)) deallocate(dummyx)
533 if (allocated(dummy)) deallocate(dummy)
534 return
535
536 end subroutine read_dragonbody_binary
537
538 !----------------------------------------------------
539 ! ascii body read
540 !----------------------------------------------------
541 subroutine read_dragonbody_ascii(iunita,ierr)
542 integer, intent(in) :: iunita
543 integer, intent(out) :: ierr
544 integer :: nerr,idumtype
545
546 !--positions
547 nerr = 0
548 do i=1,ntoti
549 read(iunita,*,end=55,iostat=ierr) dat(i,1:ndim,j)
550 if (ierr /= 0) nerr = nerr + 1
551 enddo
552 if (nerr > 0) print*,' WARNING: ',nerr,' errors reading positions '
553
554 !--velocities
555 nerr = 0
556 do i=1,ntoti
557 read(iunita,*,end=55,iostat=ierr) dat(i,ndim+1:ndim+ndimV,j)
558 if (ierr /= 0) nerr = nerr + 1
559 enddo
560 if (nerr > 0) print*,' WARNING: ',nerr,' errors reading velocities '
561
562 !--the rest
563 if (any(required(ndim+ndimV+1:nlastcol))) then
564 do icol = ndim+ndimV+1,nlastcol
565 nerr = 0
566 do i=1,ntoti
567 read(iunita,*,end=55,iostat=ierr) dat(i,icol,j)
568 if (ierr /= 0) nerr = nerr + 1
569 enddo
570 if (nerr > 0) print*,' WARNING: ',nerr,' errors reading '//trim(label(icol))
571 enddo
572 endif
573
574 !--particle type
575 if (size(iamtype(:,j)) > 1) then
576 nerr = 0
577 do i=1,ntoti
578 read(iunita,*,end=55,iostat=ierr) idumtype
579 iamtype(i,j) = idumtype
580 if (ierr /= 0) nerr = nerr + 1
581 enddo
582 if (nerr > 0) print*,' WARNING: ',nerr,' errors reading itype'
583 endif
584
585 !--the rest
586 if (any(required(nlastcol+1:nlastcol+nextracols))) then
587 do icol = nlastcol+1,nlastcol+nextracols
588 nerr = 0
589 do i=1,ntoti
590 read(iunita,*,end=55,iostat=ierr) dat(i,icol,j)
591 if (ierr /= 0) nerr = nerr + 1
592 enddo
593 if (nerr > 0) print*,' WARNING: ',nerr,' errors reading '//trim(label(icol))
594 enddo
595 endif
596
597 return
598
599 55 continue
600 print "(a)",' ERROR: end of file in ascii read'
601 ierr = -1
602 return
603
604 end subroutine read_dragonbody_ascii
605
606 !----------------------------------------------------
607 ! translate types into order (for old dragon read)
608 !----------------------------------------------------
609 subroutine set_types(itypei,ntotal,noftype)
610 integer(kind=int1), dimension(:), intent(inout) :: itypei
611 integer, intent(in) :: ntotal
612 integer, dimension(:), intent(out) :: noftype
613 integer :: ngas,nsink,nbnd,ncloud,nsplit,nunknown,nstar
614
615 !--types
616 ! 1 gas
617 ! -1 sink
618 ! -2 star
619 ! 6 boundary (fixed)
620 ! 9 intercloud (hydro only)
621 ! 4 split particle (obsolete?)
622 !
623 !--we translate these into
624 ! 1 gas
625 ! 2 boundary
626 ! 3 sink
627 ! 4 intercloud
628 ! 5 split
629 ! 6 unknown / the rest
630 ! 7 star
631 !
632 ngas = 0
633 nsink = 0
634 nbnd = 0
635 ncloud = 0
636 nsplit = 0
637 nunknown = 0
638 nstar = 0
639 do i=1,ntotal
640 select case(itypei(i))
641 case(1)
642 ngas = ngas + 1
643 itypei(i) = 1
644 case(-1)
645 nsink = nsink + 1
646 itypei(i) = 3
647 case(6)
648 nbnd = nbnd + 1
649 itypei(i) = 2
650 case(9)
651 ncloud = ncloud + 1
652 itypei(i) = 4
653 case(4)
654 nsplit = nsplit + 1
655 itypei(i) = 5
656 case(-2)
657 nstar = nstar + 1
658 itypei(i) = 6
659 case default
660 nunknown = nunknown + 1
661 ! itypei(i) = 6
662 write (6,*) "Unknown particle type ", itypei(i), "!!"
663 stop
664 end select
665 enddo
666
667 noftype(1) = ngas
668 noftype(2) = nbnd
669 noftype(3) = nsink
670 noftype(4) = ncloud
671 noftype(5) = nsplit
672 noftype(6) = nstar
673 if (sum(noftype(1:6)) /= ntotal) then
674 print "(a)",' INTERNAL ERROR setting number in each type in dragon read'
675 endif
676
677 return
678 end subroutine set_types
679
680 end subroutine read_data_dragon
681
682 !!------------------------------------------------------------
683 !! set labels for each column of data
684 !!------------------------------------------------------------
685
686 subroutine set_labels_dragon
687 use labels, only:label,iamvec,labelvec,labeltype,ix,ivx,ipmass,ih,irho
688 use params
689 use settings_data, only:ndim,ndimV,ntypes,UseTypeInRenderings
690 use geometry, only:labelcoord
691 integer :: i
692
693 if (ndim <= 0 .or. ndim > 3) then
694 print*,'*** ERROR: ndim = ',ndim,' in set_labels_dragon ***'
695 return
696 endif
697 if (ndimV <= 0 .or. ndimV > 3) then
698 print*,'*** ERROR: ndimV = ',ndimV,' in set_labels_dragon ***'
699 return
700 endif
701
702 do i=1,ndim
703 ix(i) = i
704 enddo
705 ivx = ndim+1
706 label(ivx+ndimV) = 'temperature'
707 ih = ivx + ndimV + 1
708 irho = ih + 1 ! location of rho in data array
709 ipmass = irho + 1
710 !
711 !--set labels of the quantities read in
712 !
713 label(ix(1:ndim)) = labelcoord(1:ndim,1)
714 label(irho) = 'density'
715 !label(iutherm) = 'u'
716 label(ipmass) = 'particle mass'
717 label(ih) = 'h'
718 !
719 !--set labels for vector quantities
720 !
721 iamvec(ivx:ivx+ndimV-1) = ivx
722 labelvec(ivx:ivx+ndimV-1) = 'v'
723 do i=1,ndimV
724 label(ivx+i-1) = trim(labelvec(ivx))//'\d'//labelcoord(i,1)
725 enddo
726
727 !--set labels for each particle type
728 !
729 ntypes = 6
730 labeltype(1) = 'gas'
731 labeltype(2) = 'boundary'
732 labeltype(3) = 'sink'
733 labeltype(4) = 'cloud'
734 labeltype(5) = 'split'
735 labeltype(6) = 'star'
736 UseTypeInRenderings(1) = .true.
737 UseTypeInRenderings(2) = .true.
738 UseTypeInRenderings(3) = .false.
739 UseTypeInRenderings(4) = .true.
740 UseTypeInRenderings(5) = .true.
741 UseTypeInRenderings(6) = .false.
742
743 !-----------------------------------------------------------
744 return
745 end subroutine set_labels_dragon
746
747 subroutine find_weights(out_unit_interp,out_unitzintegration,out_labelzintegration)
748 use labels, only:ipmass,ih,irho
749 use params
750 use settings_data, only:ndim
751 use unit_constants
752 use system_utils, only:get_environment_or_flag
753
754 real(doub_prec), intent(out) :: out_unit_interp
755 real, intent(out) :: out_unitzintegration
756 character(len=20), intent(out) :: out_labelzintegration
757 real(doub_prec) :: dm_unit, dh_unit, drho_unit, dr_unit
758 logical :: do_dimweight, do_zintegration
759 character(len=20) :: rho_length_label
760 real(doub_prec) :: rho_length
761 character(len=20) :: r_unit ! length unit
762 character(len=20) :: m_unit ! mass unit
763 character(len=20) :: rho_unit ! density unit
764 character(len=20) :: h_unit ! smoothing length unit
765
766 call get_environment_or_flag("DRAGON_RUNIT",r_unit)
767 call get_environment_or_flag("DRAGON_MUNIT",m_unit)
768 call get_environment_or_flag("DRAGON_RHOUNIT",rho_unit)
769 call get_environment_or_flag("DRAGON_HUNIT",H_unit)
770
771 out_unit_interp = 1.0
772 out_unitzintegration = 1.0
773 out_labelzintegration = ""
774
775 do_dimweight = .TRUE.
776 do_zintegration = .TRUE.
777
778 ! Length unit in S.I. units (m)
779 if (r_unit=="") then
780 print*,'No positions or no position units!'
781 print*,'Set environment variable DRAGON_R_UNIT to:'
782 print*,' pc, au, r_sun, r_earth, km, m, cm or 1 (dimensionless)'
783 do_zintegration = .FALSE.
784 dr_unit = 1._DP
785 elseif (r_unit=="pc") then
786 dr_unit = r_pc
787 elseif (r_unit=="au") then
788 dr_unit = r_au
789 elseif (r_unit=="r_sun") then
790 dr_unit = r_sun
791 elseif (r_unit=="r_earth") then
792 dr_unit = r_earth
793 elseif (r_unit=="km") then
794 dr_unit = 1000.0_DP
795 elseif (r_unit=="m") then
796 dr_unit = 1.0_DP
797 elseif (r_unit=="cm") then
798 dr_unit = 0.01_DP
799 elseif (r_unit=="1") then
800 dr_unit = 1._DP
801 else
802 print*,'Unknown position unit ', r_unit, '!'
803 do_zintegration = .FALSE.
804 dr_unit = 1._DP
805 endif
806
807 ! Length unit in S.I. units (m)
808 if (h_unit=="") then
809 print*,'No smoothing lengths or no smoothing length units!'
810 print*,'Set environment variable DRAGON_H_UNIT to: '
811 print*,' pc, au, r_sun, r_earth, km, m, cm or 1 (dimensionless)'
812 do_dimweight = .FALSE.
813 dh_unit = 1._DP
814 elseif (h_unit=="pc") then
815 dh_unit = r_pc
816 elseif (h_unit=="au") then
817 dh_unit = r_au
818 elseif (h_unit=="r_sun") then
819 dh_unit = r_sun
820 elseif (h_unit=="r_earth") then
821 dh_unit = r_earth
822 elseif (h_unit=="km") then
823 dh_unit = 1000.0_DP
824 elseif (h_unit=="m") then
825 dh_unit = 1.0_DP
826 elseif (h_unit=="cm") then
827 dh_unit = 0.01_DP
828 elseif (h_unit=="1") then
829 dh_unit = 1._DP
830 else
831 print*,'Unknown smoothing length unit ', h_unit, '!'
832 do_dimweight = .FALSE.
833 dh_unit = 1._DP
834 endif
835
836 ! Mass units in S.I. units (kg)
837 if (m_unit=="") then
838 print*,'No masses or no mass units!'
839 print*,'Set environment variable DRAGON_M_UNIT to:'
840 print*,' m_sun, m_jup, m_earth, kg, g or 1 (dimensionless)'
841 do_dimweight = .FALSE.
842 dm_unit = 1._DP
843 elseif (m_unit=="m_sun") then
844 dm_unit = m_sun
845 elseif (m_unit=="m_jup") then
846 dm_unit = m_jup
847 elseif (m_unit=="m_earth") then
848 dm_unit = m_earth
849 elseif (m_unit=="kg") then
850 dm_unit = 1._DP
851 elseif (m_unit=="g") then
852 dm_unit = 1.0E-3_DP
853 elseif (m_unit=="1") then
854 dm_unit = 1._DP
855 else
856 print*,'Unknown mass unit ', m_unit, '!'
857 do_dimweight = .FALSE.
858 dm_unit = 1._DP
859 endif
860
861 ! Density units in S.I. units (i.e. kg/m^3)
862 if (rho_unit=="") then
863 print*,'No densities or no density units!'
864 print*,'Set environment variable DRAGON_RHO_UNIT to:'
865 if (ndim==3) print*,' m_sun_pc3, kg_m3, g_cm3 or 1 (dimensionless)'
866 if (ndim==2) print*,' m_sun_pc2, kg_m2, g_cm2 or 1 (dimensionless)'
867 if (ndim==1) print*,' 1 (dimensionless)'
868 do_dimweight = .FALSE.
869 do_zintegration = .FALSE.
870 rho_length = 1._DP
871 elseif (rho_unit=="m_sun_pc3") then
872 drho_unit = m_sun / (r_pc**3)
873 rho_length = r_pc
874 rho_length_label = "pc"
875 elseif (rho_unit=="m_sun_pc2") then
876 drho_unit = m_sun / (r_pc**2)
877 rho_length = r_pc
878 rho_length_label = "pc"
879 elseif (rho_unit=="kg_m3") then
880 drho_unit = 1.0_DP
881 rho_length = 1.0_DP
882 rho_length_label = "m"
883 elseif (rho_unit=="kg_m2") then
884 drho_unit = 1.0_DP
885 rho_length = 1.0_DP
886 rho_length_label = "m"
887 elseif (rho_unit=="g_cm3") then
888 drho_unit = 1.0E3_DP
889 rho_length = 0.01_DP
890 rho_length_label = "cm"
891 elseif (rho_unit=="g_cm2") then
892 drho_unit = 10.0_DP
893 rho_length = 0.01_DP
894 rho_length_label = "cm"
895 elseif (rho_unit=="1") then
896 drho_unit = 1._DP
897 rho_length = 1._DP
898 rho_length_label = ""
899 else
900 print*,'Unknown density unit ', rho_unit, '!'
901 do_dimweight = .FALSE.
902 do_zintegration = .FALSE.
903 rho_length = 1._DP
904 endif
905
906 if (do_dimweight) then
907 out_unit_interp = dm_unit/(drho_unit*dh_unit**ndim)
908 else
909 print*,'Cannot create dimensionless weight'
910 print*,'(unnormalised rendered plots may be incorrect)'
911 endif
912
913 if (do_zintegration) then
914 out_unitzintegration = dr_unit / rho_length
915 out_labelzintegration = rho_length_label
916 else
917 print*,'Cannot set unitzintegration'
918 print*,'(column density plots may be incorrect)'
919 endif
920
921 return
922 end subroutine find_weights
923 end module readdata_dragon