| 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-2014 Daniel Price. All rights reserved. |
| 19 |
! Contact: [email protected] |
| 20 |
! |
| 21 |
!----------------------------------------------------------------- |
| 22 |
|
| 23 |
module particleplots |
| 24 |
implicit none |
| 25 |
public :: particleplot,plot_errorbarsx,plot_errorbarsy |
| 26 |
public :: plot_kernel_gr |
| 27 |
|
| 28 |
contains |
| 29 |
! |
| 30 |
! Drives raw particle plots |
| 31 |
! Handles different particle types, particle cross-sections, particle labelling |
| 32 |
! fast-plotting added 12.10.06 (excludes particles in crowded fields) |
| 33 |
! |
| 34 |
! Arguments: |
| 35 |
! |
| 36 |
! |
| 37 |
subroutine particleplot(x,y,z,h,ntot,iplotx,iploty,icolourpart,iamtype,noftype,iplot_type, & |
| 38 |
use_zrange,zmin,zmax,labelz,xmin,xmax,ymin,ymax, & |
| 39 |
fast,verbose,datpix,nx,ny,dval,brightness) |
| 40 |
use params, only:int1 |
| 41 |
use labels, only:labeltype, maxparttypes,is_coord |
| 42 |
use settings_data, only:ndim,icoords,ntypes |
| 43 |
use settings_part, only:imarktype,ncircpart,icoordsnew,icircpart,itypeorder, & |
| 44 |
ilabelpart,iplotline,linestylethisstep,linecolourthisstep |
| 45 |
use interpolations2D, only:interpolate_part,interpolate_part1 |
| 46 |
use transforms, only:transform |
| 47 |
use part_utils, only:igettype |
| 48 |
use sort, only:indexx |
| 49 |
use plotlib, only:plot_qci,plot_bbuf,plot_ebuf,plot_sci,plot_sfs,plot_circ, & |
| 50 |
plot_pt,plot_numb,plot_text,plot_pt1,plot_qls,plot_sls, & |
| 51 |
plot_line,plot_qlw,plot_slw,plot_errb,plotlib_maxlinestyle |
| 52 |
integer, intent(in) :: ntot,iplotx, iploty |
| 53 |
integer(kind=int1), intent(in) :: iamtype(:) |
| 54 |
integer, intent(in) :: icolourpart(:) |
| 55 |
integer, intent(in) :: noftype(maxparttypes) |
| 56 |
real, intent(in) :: x(:), y(:), z(:), h(:) |
| 57 |
real, intent(in) :: zmin,zmax,xmin,xmax,ymin,ymax |
| 58 |
logical, intent(in) :: use_zrange,fast,verbose |
| 59 |
logical, intent(in) :: iplot_type(maxparttypes) |
| 60 |
character(len=*), intent(in) :: labelz |
| 61 |
|
| 62 |
integer, intent(in), optional :: nx,ny |
| 63 |
real, intent(inout), optional :: datpix(:,:),brightness(:,:) |
| 64 |
real, intent(in), optional :: dval |
| 65 |
|
| 66 |
integer :: j,n,itype,linewidth,icolourindex,nplotted,oldlinestyle,ierr |
| 67 |
integer :: lenstring,index1,index2,ntotplot,icolourstart,nlooptypes,ilooptype |
| 68 |
integer :: nplottedtype(maxparttypes) |
| 69 |
character(len=20) :: string |
| 70 |
integer, parameter :: ncellx = 500, ncelly = 500 ! for crowded field reduction |
| 71 |
integer(kind=int1) :: nincell(ncellx,ncelly,maxparttypes) |
| 72 |
integer :: icellx,icelly,maxz |
| 73 |
real :: dx1,dy1,dxpix |
| 74 |
logical :: mixedtypes |
| 75 |
real, allocatable :: xerrb(:), yerrb(:), herr(:) |
| 76 |
integer, allocatable :: iorder(:) |
| 77 |
|
| 78 |
!--query current character height and colour |
| 79 |
call plot_qci(icolourstart) |
| 80 |
! |
| 81 |
!--check for errors in input |
| 82 |
! |
| 83 |
ntotplot = sum(noftype(1:ntypes)) |
| 84 |
if (ntot < ntotplot) then |
| 85 |
if (verbose) print "(a)",' ERROR: number of particles input < number of each type ' |
| 86 |
if (verbose) print*,ntot,noftype(1:ntypes) |
| 87 |
return |
| 88 |
elseif (ntot /= ntotplot) then |
| 89 |
if (verbose) print "(a)",' WARNING: particleplot: total not equal to sum of types on input' |
| 90 |
if (verbose) print*,' ntotal = ',ntot,' sum of types = ',ntotplot |
| 91 |
endif |
| 92 |
maxz = size(z) |
| 93 |
if (maxz > ntot) maxz = ntot |
| 94 |
if (use_zrange .and. maxz < ntot) then |
| 95 |
if (verbose) print "(a)",' WARNING: particleplot: slice plot but z array too small - excluding particles > z array size' |
| 96 |
endif |
| 97 |
dxpix = 0. |
| 98 |
if (present(datpix)) then |
| 99 |
if (.not.(present(nx).and.present(ny).and.present(dval))) then |
| 100 |
if (verbose) print "(a)",' INTERNAL ERROR in call to particleplot: optional args not present' |
| 101 |
return |
| 102 |
else |
| 103 |
dxpix = (xmax - xmin)/real(nx) |
| 104 |
endif |
| 105 |
endif |
| 106 |
|
| 107 |
! |
| 108 |
!--loop over all particle types |
| 109 |
! |
| 110 |
index1 = 1 |
| 111 |
nplottedtype = 0 |
| 112 |
nlooptypes = ntypes |
| 113 |
mixedtypes = size(iamtype) > 1 |
| 114 |
if (mixedtypes .or. use_zrange) nlooptypes = 1 |
| 115 |
dx1 = (ncellx - 1)/(xmax-xmin + tiny(xmin)) |
| 116 |
dy1 = (ncelly - 1)/(ymax-ymin + tiny(ymin)) |
| 117 |
nincell = 0 |
| 118 |
|
| 119 |
over_types: do ilooptype=1,nlooptypes |
| 120 |
call plot_bbuf !--buffer plot output until each particle type finished |
| 121 |
if (mixedtypes .or. use_zrange) then |
| 122 |
index1 = 1 |
| 123 |
index2 = ntot |
| 124 |
itype = 0 |
| 125 |
else |
| 126 |
itype = itypeorder(ilooptype) |
| 127 |
if (itype==1) then |
| 128 |
index1 = 1 |
| 129 |
else |
| 130 |
index1 = sum(noftype(1:itype-1))+1 |
| 131 |
endif |
| 132 |
index2 = index1 + noftype(itype) - 1 |
| 133 |
if (.not.iplot_type(itype)) then |
| 134 |
call plot_ebuf |
| 135 |
cycle over_types |
| 136 |
endif |
| 137 |
endif |
| 138 |
if (index2 > ntot) then |
| 139 |
index2 = ntot |
| 140 |
print "(a)",' WARNING: incomplete data' |
| 141 |
endif |
| 142 |
if (index2 < index1) then |
| 143 |
call plot_ebuf |
| 144 |
cycle over_types |
| 145 |
endif |
| 146 |
|
| 147 |
if (use_zrange) then |
| 148 |
! |
| 149 |
!--if particle cross section, plot particles only in a defined (z) coordinate range |
| 150 |
! |
| 151 |
nplotted = 0 |
| 152 |
overj: do j=1,ntot |
| 153 |
if (mixedtypes) then |
| 154 |
itype = min(max(int(iamtype(j)),1),maxparttypes) |
| 155 |
else |
| 156 |
itype = igettype(j,noftype) |
| 157 |
endif |
| 158 |
if (.not. iplot_type(itype)) cycle overj |
| 159 |
if (j <= maxz) then |
| 160 |
if (z(j) > zmin .and. z(j) < zmax) then |
| 161 |
if (icolourpart(j) >= 0) then |
| 162 |
nplotted = nplotted + 1 |
| 163 |
nplottedtype(itype) = nplottedtype(itype) + 1 |
| 164 |
|
| 165 |
if (fast .and. noftype(itype) > 100) then |
| 166 |
if (in_cell(icellx,icelly,x(j),y(j),xmin,ymin,dx1,dy1,ncellx,ncelly)) then |
| 167 |
if (nincell(icellx,icelly,itype)==0) then |
| 168 |
nincell(icellx,icelly,itype) = nincell(icellx,icelly,itype) + 1_int1 ! this +1 of type int*1 |
| 169 |
call plot_sci(icolourpart(j)) |
| 170 |
call plot_particle(imarktype(itype),x(j),y(j),h(j)) |
| 171 |
endif |
| 172 |
endif |
| 173 |
else |
| 174 |
call plot_sci(icolourpart(j)) |
| 175 |
call plot_particle(imarktype(itype),x(j),y(j),h(j)) |
| 176 |
endif |
| 177 |
|
| 178 |
if (present(datpix)) then |
| 179 |
if (present(brightness)) then |
| 180 |
call interpolate_part1(x(j),y(j),h(j),xmin,ymin,datpix,nx,ny,dxpix,dval,brightness) |
| 181 |
else |
| 182 |
call interpolate_part1(x(j),y(j),h(j),xmin,ymin,datpix,nx,ny,dxpix,dval) |
| 183 |
endif |
| 184 |
endif |
| 185 |
endif |
| 186 |
!--plot circle of interaction if gas particle |
| 187 |
if (itype==1 .and. ncircpart > 0 .and. ANY(icircpart(1:ncircpart)==j)) then |
| 188 |
call plot_circ(x(j),y(j),2*h(j)) |
| 189 |
endif |
| 190 |
!!--plot particle label |
| 191 |
if (ilabelpart) then |
| 192 |
call plot_numb(j,0,1,string,lenstring) |
| 193 |
call plot_text(x(j),y(j),string(1:lenstring)) |
| 194 |
endif |
| 195 |
endif |
| 196 |
endif |
| 197 |
enddo overj |
| 198 |
|
| 199 |
do itype=1,ntypes |
| 200 |
if (iplot_type(itype) .and. nplottedtype(itype) > 0) then |
| 201 |
if (zmin < -0.1*huge(zmin)) then |
| 202 |
if (verbose) print*,'plotted ',nplottedtype(itype),' of ',noftype(itype), & |
| 203 |
trim(labeltype(itype))//' particles with ', trim(labelz),' < ',zmax |
| 204 |
else |
| 205 |
if (verbose) print*,'plotted ',nplottedtype(itype),' of ',noftype(itype), & |
| 206 |
trim(labeltype(itype))//' particles in range ', trim(labelz),' = ',zmin,' -> ',zmax |
| 207 |
endif |
| 208 |
endif |
| 209 |
enddo |
| 210 |
else |
| 211 |
! |
| 212 |
!--otherwise plot all particles of this type using appropriate marker and colour |
| 213 |
! |
| 214 |
call plot_qci(icolourindex) |
| 215 |
! |
| 216 |
!--all particles in range have same colour and type |
| 217 |
! |
| 218 |
if (.not.mixedtypes .and. all(icolourpart(index1:index2)==icolourpart(index1)) & |
| 219 |
.and. icolourpart(index1) >= 0) then |
| 220 |
call plot_sci(icolourpart(index1)) |
| 221 |
if (fast .and. (index2-index1) > 100) then |
| 222 |
!--fast-plotting only allows one particle per "grid cell" - avoids crowded fields |
| 223 |
if (verbose) write(*,"(a,i8,1x,a)") ' fast-plotting ',index2-index1+1,trim(labeltype(itype))//' particles' |
| 224 |
nincell = 0 |
| 225 |
do j=index1,index2 |
| 226 |
if (in_cell(icellx,icelly,x(j),y(j),xmin,ymin,dx1,dy1,ncellx,ncelly)) then |
| 227 |
if (nincell(icellx,icelly,itype)==0) then |
| 228 |
nincell(icellx,icelly,itype) = nincell(icellx,icelly,itype) + 1_int1 ! this +1 of type int*1 |
| 229 |
|
| 230 |
call plot_particle(imarktype(itype),x(j),y(j),h(j)) |
| 231 |
|
| 232 |
if (present(datpix)) then |
| 233 |
if (present(brightness)) then |
| 234 |
call interpolate_part1(x(j),y(j),h(j),xmin,ymin,datpix,nx,ny,dxpix,dval,brightness) |
| 235 |
else |
| 236 |
call interpolate_part1(x(j),y(j),h(j),xmin,ymin,datpix,nx,ny,dxpix,dval) |
| 237 |
endif |
| 238 |
endif |
| 239 |
endif |
| 240 |
endif |
| 241 |
enddo |
| 242 |
else |
| 243 |
!--plot all particles of this type |
| 244 |
if (verbose) print "(a,i8,1x,a)",' plotting ',index2-index1+1,trim(labeltype(itype))//' particles' |
| 245 |
select case(imarktype(itype)) |
| 246 |
case(32:35) |
| 247 |
do j=index1,index2 |
| 248 |
call plot_particle(imarktype(itype),x(j),y(j),h(j)) |
| 249 |
enddo |
| 250 |
call plot_sfs(1) |
| 251 |
case default |
| 252 |
call plot_pt(noftype(itype),x(index1:index2),y(index1:index2),imarktype(itype)) |
| 253 |
end select |
| 254 |
if (present(datpix)) then |
| 255 |
if (present(brightness)) then |
| 256 |
call interpolate_part(x(index1:index2),y(index1:index2),h(index1:index2), & |
| 257 |
noftype(itype),xmin,ymin,datpix,nx,ny,dxpix,dval,brightness) |
| 258 |
else |
| 259 |
call interpolate_part(x(index1:index2),y(index1:index2),h(index1:index2), & |
| 260 |
noftype(itype),xmin,ymin,datpix,nx,ny,dxpix,dval) |
| 261 |
endif |
| 262 |
endif |
| 263 |
endif |
| 264 |
else |
| 265 |
! |
| 266 |
!--mixed colours and/or mixed types |
| 267 |
! |
| 268 |
nplotted = 0 |
| 269 |
nplottedtype = 0 |
| 270 |
|
| 271 |
overj2: do j=index1,index2 |
| 272 |
if (icolourpart(j) >= 0) then |
| 273 |
if (mixedtypes) then |
| 274 |
itype = int(iamtype(j)) |
| 275 |
if (.not.iplot_type(itype)) cycle overj2 |
| 276 |
nplottedtype(itype) = nplottedtype(itype) + 1 |
| 277 |
endif |
| 278 |
nplotted = nplotted + 1 |
| 279 |
if (fast .and. noftype(itype) > 100) then |
| 280 |
if (in_cell(icellx,icelly,x(j),y(j),xmin,ymin,dx1,dy1,ncellx,ncelly)) then |
| 281 |
!--exclude particles if there are more than 2 particles per cell |
| 282 |
! (two here because particles can have different colours) |
| 283 |
if (nincell(icellx,icelly,itype) <= 0) then |
| 284 |
nincell(icellx,icelly,itype) = nincell(icellx,icelly,itype) + 1_int1 ! this +1 of type int*1 |
| 285 |
|
| 286 |
call plot_sci(icolourpart(j)) |
| 287 |
call plot_particle(imarktype(itype),x(j),y(j),h(j)) |
| 288 |
|
| 289 |
if (present(datpix)) then |
| 290 |
if (present(brightness)) then |
| 291 |
call interpolate_part1(x(j),y(j),h(j),xmin,ymin,datpix,nx,ny,dxpix,dval,brightness) |
| 292 |
else |
| 293 |
call interpolate_part1(x(j),y(j),h(j),xmin,ymin,datpix,nx,ny,dxpix,dval) |
| 294 |
endif |
| 295 |
endif |
| 296 |
endif |
| 297 |
endif |
| 298 |
else |
| 299 |
call plot_sci(icolourpart(j)) |
| 300 |
call plot_particle(imarktype(itype),x(j),y(j),h(j)) |
| 301 |
|
| 302 |
if (present(datpix)) then |
| 303 |
if (present(brightness)) then |
| 304 |
call interpolate_part1(x(j),y(j),h(j),xmin,ymin,datpix,nx,ny,dxpix,dval,brightness) |
| 305 |
else |
| 306 |
call interpolate_part1(x(j),y(j),h(j),xmin,ymin,datpix,nx,ny,dxpix,dval) |
| 307 |
endif |
| 308 |
endif |
| 309 |
endif |
| 310 |
endif |
| 311 |
enddo overj2 |
| 312 |
if (mixedtypes) then |
| 313 |
do itype=1,ntypes |
| 314 |
if (iplot_type(itype)) then |
| 315 |
if (fast .and. noftype(itype) > 100) then |
| 316 |
if (verbose) print*,' fast-plotted ',nplottedtype(itype),& |
| 317 |
' of ',noftype(itype),trim(labeltype(itype))//' particles' |
| 318 |
elseif (noftype(itype) > 0) then |
| 319 |
if (verbose) print*,' plotted ',nplottedtype(itype),& |
| 320 |
' of ',noftype(itype),trim(labeltype(itype))//' particles' |
| 321 |
endif |
| 322 |
endif |
| 323 |
enddo |
| 324 |
else |
| 325 |
if (fast .and. noftype(itype) > 100) then |
| 326 |
if (verbose) print*,' fast-plotted ',nplotted,' of ',index2-index1+1,trim(labeltype(itype))//' particles' |
| 327 |
else |
| 328 |
if (verbose) print*,' plotted ',nplotted,' of ',index2-index1+1,trim(labeltype(itype))//' particles' |
| 329 |
endif |
| 330 |
endif |
| 331 |
endif |
| 332 |
call plot_sci(icolourindex) |
| 333 |
|
| 334 |
if (ilabelpart) then |
| 335 |
!!--plot particle labels |
| 336 |
if (verbose) print*,'plotting particle labels ',index1,':',index2 |
| 337 |
do j=index1,index2 |
| 338 |
call plot_numb(j,0,1,string,lenstring) |
| 339 |
call plot_text(x(j),y(j),string(1:lenstring)) |
| 340 |
enddo |
| 341 |
endif |
| 342 |
endif |
| 343 |
index1 = index2 + 1 |
| 344 |
call plot_ebuf !--flush PGPLOT buffer at end of each type |
| 345 |
enddo over_types |
| 346 |
|
| 347 |
! |
| 348 |
!--plot lines joining particles if relevant |
| 349 |
! |
| 350 |
call plot_qci(icolourindex) |
| 351 |
call plot_sci(linecolourthisstep) |
| 352 |
! i.e., don't plot a line for cross section plots (would plot all particles) |
| 353 |
! but do if there is 3D perspective --> in which case zmin = -huge(x) |
| 354 |
if (iplotline .and. .not.(use_zrange .and. abs(zmax-zmin) < 0.5*huge(0.))) then |
| 355 |
call plot_qls(oldlinestyle) |
| 356 |
call plot_sls(linestylethisstep) |
| 357 |
if (ndim <= 1 .and. .false.) then ! sort particles by x in 1D |
| 358 |
allocate(iorder(noftype(1))) |
| 359 |
call indexx(noftype(1),x(1:noftype(1)),iorder) |
| 360 |
call plot_line(noftype(1),x(iorder),y(iorder)) |
| 361 |
deallocate(iorder) |
| 362 |
else |
| 363 |
call plot_line(noftype(1),x(1:noftype(1)),y(1:noftype(1))) |
| 364 |
endif |
| 365 |
if (noftype(2) > 0 .and. iplot_type(2)) then |
| 366 |
call plot_sls(mod(linestylethisstep+1,plotlib_maxlinestyle) + 1) |
| 367 |
call plot_line(noftype(2),x(noftype(1)+1:sum(noftype(1:2))),y(noftype(1)+1:sum(noftype(1:2)))) |
| 368 |
endif |
| 369 |
call plot_sls(oldlinestyle)! reset |
| 370 |
endif |
| 371 |
|
| 372 |
call plot_sci(icolourindex) |
| 373 |
! |
| 374 |
!--plot circles of interaction (ie a circle of radius 2h) |
| 375 |
! around all or selected particles. For plots with only one coordinate axis, |
| 376 |
! these are plotted as error bars in the coordinate direction. |
| 377 |
! |
| 378 |
!--this bit is also used for error bar plotting on x or y axis. |
| 379 |
! |
| 380 |
if (ncircpart > 0) then |
| 381 |
! |
| 382 |
!--set fill area style and line width |
| 383 |
! |
| 384 |
call plot_qlw(linewidth) |
| 385 |
call plot_slw(2) |
| 386 |
call plot_qci(icolourindex) |
| 387 |
call plot_sci(2) |
| 388 |
call plot_sfs(2) |
| 389 |
|
| 390 |
if (ncircpart > 0) then |
| 391 |
|
| 392 |
if (is_coord(iplotx,ndim) .and. is_coord(iploty,ndim) .and. ncircpart > 0) then |
| 393 |
if (verbose) print*,'plotting ',ncircpart,' circles of interaction' |
| 394 |
do n = 1,ncircpart |
| 395 |
if (icircpart(n) > ntot) then |
| 396 |
if (verbose) print*,'error: particle index > number of particles' |
| 397 |
else |
| 398 |
if (icoordsnew /= icoords) then |
| 399 |
call plot_kernel_gr(icoordsnew,icoords,iplotx,iploty,& |
| 400 |
x(icircpart(n)),y(icircpart(n)),z(icircpart(n)),2*h(icircpart(n))) |
| 401 |
else |
| 402 |
call plot_circ(x(icircpart(n)),y(icircpart(n)),2*h(icircpart(n))) |
| 403 |
endif |
| 404 |
endif |
| 405 |
enddo |
| 406 |
else |
| 407 |
if (.not.allocated(herr)) then |
| 408 |
allocate(xerrb(ncircpart),yerrb(ncircpart),herr(ncircpart),stat=ierr) |
| 409 |
if (ierr /= 0) then |
| 410 |
print "(a)",' Error allocating memory in particleplot for circles of interaction' |
| 411 |
return |
| 412 |
endif |
| 413 |
endif |
| 414 |
!!--only on specified particles |
| 415 |
do n=1,ncircpart |
| 416 |
if (icircpart(n) > ntot) then |
| 417 |
print*,'error: particle index > number of particles' |
| 418 |
xerrb(n) = 0. |
| 419 |
yerrb(n) = 0. |
| 420 |
herr(n) = 0. |
| 421 |
else |
| 422 |
xerrb(n) = x(icircpart(n)) |
| 423 |
yerrb(n) = y(icircpart(n)) |
| 424 |
herr(n) = 2.*h(icircpart(n)) |
| 425 |
endif |
| 426 |
enddo |
| 427 |
if (is_coord(iplotx,ndim)) then |
| 428 |
if (verbose) print*,'plotting ',ncircpart,' error bars x axis ' |
| 429 |
call plot_errb(5,ncircpart,xerrb(1:ncircpart),yerrb(1:ncircpart),herr(1:ncircpart),1.0) |
| 430 |
elseif (is_coord(iploty,ndim)) then |
| 431 |
if (verbose) print*,'plotting ',ncircpart,' error bars y axis' |
| 432 |
call plot_errb(6,ncircpart,xerrb(1:ncircpart),yerrb(1:ncircpart),herr(1:ncircpart),1.0) |
| 433 |
endif |
| 434 |
if (allocated(herr)) deallocate(herr) |
| 435 |
if (allocated(xerrb)) deallocate(xerrb) |
| 436 |
if (allocated(yerrb)) deallocate(yerrb) |
| 437 |
endif |
| 438 |
endif |
| 439 |
|
| 440 |
call plot_slw(linewidth) |
| 441 |
call plot_sci(icolourindex) |
| 442 |
|
| 443 |
endif |
| 444 |
|
| 445 |
! |
| 446 |
!--reset colour |
| 447 |
! |
| 448 |
call plot_sci(icolourstart) |
| 449 |
|
| 450 |
return |
| 451 |
|
| 452 |
end subroutine particleplot |
| 453 |
!-------------------------------------------------------------------------------- |
| 454 |
! |
| 455 |
! subroutine implementing scalable markers |
| 456 |
! default case is just an interface to usual particle plotting routine |
| 457 |
! |
| 458 |
!-------------------------------------------------------------------------------- |
| 459 |
subroutine plot_particle(imarktype,x,y,h) |
| 460 |
use plotlib, only:plot_circ,plot_sfs,plot_sci,plot_pt1 |
| 461 |
use settings_part, only:hfacmarkers |
| 462 |
integer, intent(in) :: imarktype |
| 463 |
real, intent(in) :: x,y,h |
| 464 |
integer :: imarker |
| 465 |
real :: size |
| 466 |
|
| 467 |
if (h < 0.) return ! this will prevent plotting of merged sinks in Phantom |
| 468 |
|
| 469 |
select case(imarktype) |
| 470 |
case(32:35) |
| 471 |
imarker = imarktype - 31 |
| 472 |
size = hfacmarkers*h |
| 473 |
! also plot point in centre in case circle is too small |
| 474 |
! but only if marker type is solid fill |
| 475 |
if (imarker /= 2) call plot_pt1(x,y,1) |
| 476 |
if (imarker <= 2) then ! solid circle |
| 477 |
call plot_sfs(imarker) |
| 478 |
call plot_circ(x,y,size) |
| 479 |
call plot_sfs(1) |
| 480 |
elseif (imarker==3) then ! open circle |
| 481 |
call plot_sfs(1) |
| 482 |
call plot_circ(x,y,size) |
| 483 |
call plot_sfs(2) |
| 484 |
call plot_sci(0) |
| 485 |
call plot_circ(x,y,size) |
| 486 |
call plot_sfs(1) |
| 487 |
elseif (imarker==4) then ! outlined solid circle |
| 488 |
call plot_sfs(1) |
| 489 |
call plot_circ(x,y,size) |
| 490 |
call plot_sfs(2) |
| 491 |
call plot_sci(1) |
| 492 |
call plot_circ(x,y,size) |
| 493 |
call plot_sfs(1) |
| 494 |
else |
| 495 |
call plot_circ(x,y,size) |
| 496 |
endif |
| 497 |
case default |
| 498 |
call plot_pt1(x,y,imarktype) |
| 499 |
end select |
| 500 |
|
| 501 |
end subroutine plot_particle |
| 502 |
!------------------------------------------------------------ |
| 503 |
! |
| 504 |
! function used to determine which cell a particle lies in |
| 505 |
! returns TRUE if within allowed limits, FALSE if not |
| 506 |
! |
| 507 |
!------------------------------------------------------------ |
| 508 |
logical function in_cell(ix,iy,x,y,xmin,ymin,dx1,dy1,nx,ny) |
| 509 |
integer, intent(out) :: ix,iy |
| 510 |
real, intent(in) :: x,y,xmin,ymin,dx1,dy1 |
| 511 |
integer, intent(in) :: nx,ny |
| 512 |
|
| 513 |
ix = int((x - xmin)*dx1) + 1 |
| 514 |
iy = int((y - ymin)*dy1) + 1 |
| 515 |
!--exclude particles if there are more than 2 particles per cell |
| 516 |
! (two here because particles can have different colours) |
| 517 |
in_cell = (ix > 0 .and. ix <= nx .and. iy > 0 .and. iy <= ny) |
| 518 |
|
| 519 |
end function in_cell |
| 520 |
|
| 521 |
!-------------------------------------------------------------------------------- |
| 522 |
! |
| 523 |
! subroutine to plot the circle of interaction for a given particle |
| 524 |
! in general coordinate systems (e.g. cylindrical coordinates) |
| 525 |
! |
| 526 |
! input: igeom : coordinate system (0,1=cartesian, 2=cylindrical, 3=spherical) |
| 527 |
! x,y : particle location in cartesian space |
| 528 |
! h : size of smoothing sphere |
| 529 |
! (assumed isotropic in coordinate space) |
| 530 |
! |
| 531 |
! PGPLOT page must already be set up - this just draws the "circle" |
| 532 |
! |
| 533 |
!-------------------------------------------------------------------------------- |
| 534 |
subroutine plot_kernel_gr(igeom,igeomold,iplotx,iploty,x,y,z,h) |
| 535 |
use geometry, only:coord_transform,maxcoordsys,labelcoordsys |
| 536 |
use plotlib, only:plot_line |
| 537 |
use labels, only:ix |
| 538 |
integer, intent(in) :: igeom,igeomold,iplotx,iploty |
| 539 |
real, intent(in) :: x,y,z,h |
| 540 |
|
| 541 |
integer, parameter :: npts = 100 ! big enough to give a smooth circle |
| 542 |
real, parameter :: pi = 3.1415926536 |
| 543 |
integer :: i,iplotz |
| 544 |
real, dimension(3) :: xtemp,xplot_coords |
| 545 |
real, dimension(3,npts) :: xpts |
| 546 |
real :: angle, dangle, xi, yi, zi |
| 547 |
|
| 548 |
if (igeom > 1 .and. igeom <= maxcoordsys) then |
| 549 |
print 10,labelcoordsys(igeom) |
| 550 |
else |
| 551 |
print 10,labelcoordsys(1) |
| 552 |
endif |
| 553 |
10 format('coordinate system = ',a) |
| 554 |
|
| 555 |
iplotz = 0 |
| 556 |
do i=1,3 |
| 557 |
if (iplotx /= ix(i) .and. iploty /= ix(i)) iplotz = ix(i) |
| 558 |
enddo |
| 559 |
if (iplotz==0) return |
| 560 |
|
| 561 |
xplot_coords = (/x,y,z/) ! not actual x,y,z |
| 562 |
xtemp(iplotx-ix(1)+1) = xplot_coords(1) |
| 563 |
xtemp(iploty-ix(1)+1) = xplot_coords(2) |
| 564 |
xtemp(iplotz-ix(1)+1) = xplot_coords(3) |
| 565 |
!--e.g. from cylindricals TO cartesians |
| 566 |
call coord_transform(xtemp,3,igeom,xpts(:,1),3,igeomold) |
| 567 |
xi = xpts(1,1) |
| 568 |
yi = xpts(2,1) |
| 569 |
zi = xpts(3,1) |
| 570 |
! |
| 571 |
!--step around a circle in co-ordinate space of radius h and store the |
| 572 |
! location of the points in cartesian space in the 2D array xpts |
| 573 |
! |
| 574 |
dangle = 2.*pi/REAL(npts-1) |
| 575 |
do i=1,npts |
| 576 |
angle = (i-1)*dangle |
| 577 |
xtemp(1) = xi + h*cos(angle) |
| 578 |
xtemp(2) = yi + h*sin(angle) |
| 579 |
xtemp(3) = zi |
| 580 |
! |
| 581 |
!--translate back to actual coordinate system plotted |
| 582 |
! |
| 583 |
call coord_transform(xtemp,3,igeomold,xpts(:,i),3,igeom) |
| 584 |
enddo |
| 585 |
! |
| 586 |
!--now plot the circle using pgline |
| 587 |
! |
| 588 |
call plot_line(npts,xpts(iplotx-ix(1)+1,:),xpts(iploty-ix(1)+1,:)) |
| 589 |
|
| 590 |
return |
| 591 |
end subroutine plot_kernel_gr |
| 592 |
|
| 593 |
!-------------------------------------------------------------------------------- |
| 594 |
! |
| 595 |
! Plot y-axis error bars, handling the case where the axes are transformed |
| 596 |
! |
| 597 |
! input x,y are in transformed space (i.e., already logged) |
| 598 |
! input err is not transformed, (i.e., not logged) |
| 599 |
! |
| 600 |
!-------------------------------------------------------------------------------- |
| 601 |
subroutine plot_errorbarsy(npts,x,y,err,itrans) |
| 602 |
use plotlib, only:plot_bbuf,plot_ebuf,plot_err1,plot_errb |
| 603 |
use transforms, only:transform,transform_inverse,islogged |
| 604 |
use settings_part, only:ErrorBarType |
| 605 |
use settings_data, only:iverbose |
| 606 |
integer, intent(in) :: npts,itrans |
| 607 |
real, intent(in), dimension(:) :: x,y,err |
| 608 |
real :: yval,errval |
| 609 |
real, dimension(2) :: val |
| 610 |
real, dimension(npts) :: errp,errm |
| 611 |
integer :: i |
| 612 |
|
| 613 |
if (iverbose >= 1) then |
| 614 |
if (npts < 10000) then |
| 615 |
print "(a,i4,a)",' plotting ',npts,' error bars y axis' |
| 616 |
else |
| 617 |
print "(a,i10,a)",' plotting ',npts,' error bars y axis' |
| 618 |
endif |
| 619 |
endif |
| 620 |
if (itrans /= 0) then |
| 621 |
if (islogged(itrans)) then |
| 622 |
errval = 0. !-300. |
| 623 |
else |
| 624 |
errval = 0. |
| 625 |
endif |
| 626 |
!call plot_bbuf |
| 627 |
do i=1,npts |
| 628 |
yval = y(i) |
| 629 |
call transform_inverse(yval,itrans) |
| 630 |
val(1) = yval + err(i) |
| 631 |
val(2) = yval - err(i) |
| 632 |
call transform(val,itrans,errval=errval) |
| 633 |
errp(i) = val(1) - y(i) |
| 634 |
errm(i) = y(i) - val(2) |
| 635 |
val(1) = val(1) - y(i) |
| 636 |
val(2) = y(i) - val(2) |
| 637 |
if (ErrorBarType /= 1) then |
| 638 |
call plot_err1(2,x(i),y(i),val(1),1.0) |
| 639 |
call plot_err1(4,x(i),y(i),val(2),1.0) |
| 640 |
endif |
| 641 |
enddo |
| 642 |
if (ErrorBarType==1) then |
| 643 |
call plot_errb(7,npts,x,y,errp,1.0) |
| 644 |
call plot_errb(8,npts,x,y,errm,1.0) |
| 645 |
endif |
| 646 |
!call plot_ebuf |
| 647 |
else |
| 648 |
if (ErrorBarType==1) then |
| 649 |
call plot_errb(9,npts,x,y,err,1.0) |
| 650 |
else |
| 651 |
call plot_errb(6,npts,x,y,err,1.0) |
| 652 |
endif |
| 653 |
endif |
| 654 |
|
| 655 |
end subroutine plot_errorbarsy |
| 656 |
|
| 657 |
!-------------------------------------------------------------------------------- |
| 658 |
! |
| 659 |
! Plot x-axis error bars, handling the case where the axes are transformed |
| 660 |
! |
| 661 |
! input x,y are in transformed space (i.e., already logged) |
| 662 |
! input err is not transformed, (i.e., not logged) |
| 663 |
! |
| 664 |
!-------------------------------------------------------------------------------- |
| 665 |
subroutine plot_errorbarsx(npts,x,y,err,itrans) |
| 666 |
use transforms, only:transform,transform_inverse,islogged |
| 667 |
use plotlib, only:plot_bbuf,plot_ebuf,plot_err1,plot_errb |
| 668 |
integer, intent(in) :: npts,itrans |
| 669 |
real, intent(in), dimension(:) :: x,y,err |
| 670 |
real :: xval,errval |
| 671 |
real, dimension(2) :: val |
| 672 |
integer :: i |
| 673 |
|
| 674 |
print*,'plotting ',npts,' error bars x axis ' |
| 675 |
if (itrans /= 0) then |
| 676 |
if (islogged(itrans)) then |
| 677 |
errval = -300. |
| 678 |
else |
| 679 |
errval = 0. |
| 680 |
endif |
| 681 |
call plot_bbuf |
| 682 |
do i=1,npts |
| 683 |
xval = x(i) |
| 684 |
call transform_inverse(xval,itrans) |
| 685 |
val(1) = xval + err(i) |
| 686 |
val(2) = xval - err(i) |
| 687 |
call transform(val,itrans,errval=errval) |
| 688 |
val(1) = val(1) - x(i) |
| 689 |
val(2) = x(i) - val(2) |
| 690 |
call plot_err1(1,x(i),y(i),val(1),1.0) |
| 691 |
call plot_err1(3,x(i),y(i),val(2),1.0) |
| 692 |
enddo |
| 693 |
call plot_ebuf |
| 694 |
else |
| 695 |
call plot_errb(5,npts,x,y,err,1.0) |
| 696 |
endif |
| 697 |
|
| 698 |
end subroutine plot_errorbarsx |
| 699 |
|
| 700 |
end module particleplots |