| 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-2023 Daniel Price. All rights reserved. |
| 19 |
! Contact: [email protected] |
| 20 |
! |
| 21 |
!----------------------------------------------------------------- |
| 22 |
|
| 23 |
!----------------------------------------------------------- |
| 24 |
! |
| 25 |
! routines to do with storing and handling of plot labels |
| 26 |
! |
| 27 |
!----------------------------------------------------------- |
| 28 |
module labels |
| 29 |
use params, only:maxplot,maxparttypes,maxhdr,ltag |
| 30 |
use asciiutils, only:count_non_blank |
| 31 |
implicit none |
| 32 |
integer, parameter :: lenlabel = 80 |
| 33 |
integer, parameter :: lenunitslabel = 40 ! length of units label |
| 34 |
character(len=lenlabel), dimension(maxplot+2) :: label,labelvec,labelreq,labelorig |
| 35 |
character(len=ltag), dimension(maxhdr) :: headertags |
| 36 |
character(len=20), dimension(maxparttypes) :: labeltype |
| 37 |
character(len=6), parameter :: labeldefault = 'column' |
| 38 |
character(len=lenunitslabel), dimension(0:maxplot), public :: unitslabel,unitslabel_default |
| 39 |
character(len=lenunitslabel) :: labelzintegration,labelzintegration_default |
| 40 |
integer, dimension(3) :: ix |
| 41 |
integer, dimension(maxplot) :: iamvec |
| 42 |
integer :: ivx,irho,iutherm,ipr,ih,irad,iBfirst,iBpol,iBtor,iax |
| 43 |
integer :: ipmass,ike,ispsound,itemp,ikappa |
| 44 |
integer :: idivb,iJfirst,irhostar,ipmomx |
| 45 |
integer :: iacplane,ipowerspec |
| 46 |
integer :: icv,iradenergy,iradFx |
| 47 |
integer :: isurfdens,itoomre,iomegasq |
| 48 |
integer :: ipdf,icolpixmap |
| 49 |
integer :: irhorestframe,idustfrac,ideltav |
| 50 |
integer :: idustfracsum,ideltavsum |
| 51 |
integer :: igrainsize,igraindens,ivrel |
| 52 |
integer :: irhodust_start,irhodust_end |
| 53 |
integer :: nreq |
| 54 |
|
| 55 |
public |
| 56 |
|
| 57 |
contains |
| 58 |
|
| 59 |
!-------------------------------------------------------------- |
| 60 |
! |
| 61 |
! utility to reset default settings for column identification |
| 62 |
! |
| 63 |
!-------------------------------------------------------------- |
| 64 |
subroutine reset_columnids |
| 65 |
! |
| 66 |
!--array positions of specific quantities |
| 67 |
! Identification is used in exact solution |
| 68 |
! plotting and calculation of additional quantities |
| 69 |
! |
| 70 |
ix(:) = 0 |
| 71 |
ivx = 0 ! vx |
| 72 |
irho = 0 ! density |
| 73 |
ipr = 0 ! pressure |
| 74 |
iutherm = 0 ! thermal energy |
| 75 |
ih = 0 ! smoothing length |
| 76 |
irad = 0 ! radius |
| 77 |
ipmass = 0 ! particle mass |
| 78 |
ipr = 0 ! pressure |
| 79 |
irad = 0 ! radius |
| 80 |
ipowerspec = 0 ! power spectrum |
| 81 |
iBfirst = 0 ! Bx |
| 82 |
iax = 0 ! ax (acceleration) |
| 83 |
iBpol = 0 ! B_polx |
| 84 |
iBtor = 0 ! B_torx |
| 85 |
igrainsize = 0 ! grainsize |
| 86 |
igraindens = 0 ! graindens |
| 87 |
ivrel = 0 ! relative velocity |
| 88 |
itemp = 0 ! temperature |
| 89 |
ikappa = 0 ! opacity |
| 90 |
iradFx = 0 |
| 91 |
iacplane = 0 |
| 92 |
ike = 0 |
| 93 |
idivB = 0 |
| 94 |
iJfirst = 0 |
| 95 |
icv = 0 |
| 96 |
iradenergy = 0 |
| 97 |
icolpixmap = 0 |
| 98 |
irhorestframe = 0 |
| 99 |
idustfrac = 0 |
| 100 |
idustfracsum = 0 |
| 101 |
ideltav = 0 |
| 102 |
ideltavsum = 0 |
| 103 |
ipmomx = 0 |
| 104 |
irhodust_start = 0 |
| 105 |
irhodust_end = 0 |
| 106 |
headertags = '' |
| 107 |
|
| 108 |
end subroutine reset_columnids |
| 109 |
|
| 110 |
!-------------------------------------------------------------- |
| 111 |
! |
| 112 |
! set default column labels |
| 113 |
! |
| 114 |
!-------------------------------------------------------------- |
| 115 |
subroutine set_default_labels(mylabel) |
| 116 |
character(len=*), intent(out) :: mylabel(:) |
| 117 |
integer :: i |
| 118 |
|
| 119 |
do i=1,size(mylabel) |
| 120 |
write(mylabel(i),"(a,1x,i3)") trim(labeldefault),i |
| 121 |
enddo |
| 122 |
|
| 123 |
end subroutine set_default_labels |
| 124 |
|
| 125 |
!-------------------------------------------------------------- |
| 126 |
! |
| 127 |
! query function for whether column is a spatial coordinate |
| 128 |
! |
| 129 |
!-------------------------------------------------------------- |
| 130 |
logical function is_coord(icol,ndim) |
| 131 |
integer, intent(in) :: icol,ndim |
| 132 |
integer :: i |
| 133 |
|
| 134 |
is_coord = .false. |
| 135 |
do i=1,ndim |
| 136 |
if (ix(i)==icol) is_coord = .true. |
| 137 |
enddo |
| 138 |
|
| 139 |
end function is_coord |
| 140 |
|
| 141 |
!-------------------------------------------------------------- |
| 142 |
! |
| 143 |
! query function for whether column is a density |
| 144 |
! mainly used to decide whether or not to use |
| 145 |
! mass-weighted interpolation |
| 146 |
! |
| 147 |
!-------------------------------------------------------------- |
| 148 |
logical function is_density(icol) |
| 149 |
integer, intent(in) :: icol |
| 150 |
|
| 151 |
is_density = .false. |
| 152 |
|
| 153 |
! if we match known density columns |
| 154 |
if (icol==irho .or. icol==irhorestframe) is_density = .true. |
| 155 |
|
| 156 |
! if label contains rho or dens |
| 157 |
if (icol > 0 .and. icol < size(label)) then |
| 158 |
if (index(label(icol),'rho') > 0) is_density = .true. |
| 159 |
if (index(label(icol),'dens') > 0) is_density = .true. |
| 160 |
else |
| 161 |
is_density = .true. ! icol = 0 should be true |
| 162 |
endif |
| 163 |
|
| 164 |
end function is_density |
| 165 |
|
| 166 |
!---------------------------------------------------------------- |
| 167 |
! |
| 168 |
! function returning the synonym of a label |
| 169 |
! so two different labels can be identified as the same |
| 170 |
! physical quantity, e.g. "radius" and "r" are both the radius |
| 171 |
! |
| 172 |
!---------------------------------------------------------------- |
| 173 |
elemental function label_synonym(string) |
| 174 |
use asciiutils, only:lcase,string_delete |
| 175 |
character(len=*), intent(in) :: string |
| 176 |
character(len=max(len(string),8)) :: label_synonym |
| 177 |
character(len=len(string)) :: labeli |
| 178 |
integer :: k |
| 179 |
|
| 180 |
! remove leading spaces and make lower case |
| 181 |
labeli = trim(adjustl(lcase(string))) |
| 182 |
|
| 183 |
! split at whitespace or [ to avoid unit labels |
| 184 |
k = max(index(labeli,' '),index(labeli,'[')) |
| 185 |
if (k > 1) then |
| 186 |
labeli = labeli(1:k-1) |
| 187 |
endif |
| 188 |
! also remove special characters |
| 189 |
call string_delete(labeli,'\d') |
| 190 |
call string_delete(labeli,'\u') |
| 191 |
call string_delete(labeli,'\') |
| 192 |
call string_delete(labeli,'_') |
| 193 |
|
| 194 |
! remove log from the front of the label |
| 195 |
if (labeli(1:3)=='log') labeli = labeli(4:) |
| 196 |
|
| 197 |
if (labeli(1:3)=='den' .or. index(labeli,'rho') /= 0 .or. labeli(1:2)=='gr' .or. & |
| 198 |
(index(labeli,'density') /= 0 .and. irho==0)) then |
| 199 |
label_synonym = 'density' |
| 200 |
elseif (labeli(1:5)=='pmass' .or. labeli(1:13)=='particle mass') then |
| 201 |
label_synonym = 'pmass' |
| 202 |
elseif (trim(labeli)=='h' .or. labeli(1:6)=='smooth') then |
| 203 |
label_synonym = 'h' |
| 204 |
elseif (trim(labeli)=='u' .or. labeli(1:6)=='utherm' .or. labeli(1:5)=='eint' & |
| 205 |
.or.(index(labeli,'internal energy') /= 0)) then |
| 206 |
label_synonym = 'u' |
| 207 |
elseif (labeli(1:2)=='pr' .or. trim(labeli)=='p' .or. & |
| 208 |
(index(labeli,'pressure') /= 0 .and. ipr==0)) then |
| 209 |
label_synonym = 'pressure' |
| 210 |
elseif (trim(labeli)=='r' .or. labeli(1:3)=='rad') then |
| 211 |
label_synonym = 'radius' |
| 212 |
else |
| 213 |
! by default the label synonym is the same as the original label |
| 214 |
label_synonym = labeli |
| 215 |
endif |
| 216 |
|
| 217 |
end function label_synonym |
| 218 |
|
| 219 |
!-------------------------------------------------------------- |
| 220 |
! |
| 221 |
! query function for whether column is a spatial coordinate |
| 222 |
! returns the location of the third dimension in the |
| 223 |
! list of columns |
| 224 |
! |
| 225 |
!-------------------------------------------------------------- |
| 226 |
integer function get_z_dir(ndim,iplotx,iploty) result(iplotz) |
| 227 |
integer, intent(in) :: ndim,iplotx,iploty |
| 228 |
integer :: i |
| 229 |
|
| 230 |
iplotz = 0 |
| 231 |
do i=1,ndim |
| 232 |
if ((iplotx /= iploty.and. & |
| 233 |
(ix(i) /= iplotx).and.(ix(i) /= iploty))) iplotz = ix(i) |
| 234 |
enddo |
| 235 |
|
| 236 |
end function get_z_dir |
| 237 |
|
| 238 |
!-------------------------------------------------------------- |
| 239 |
! |
| 240 |
! query function for which coordinate is z |
| 241 |
! returns an integer between 1 and ndim |
| 242 |
! |
| 243 |
!-------------------------------------------------------------- |
| 244 |
integer function get_z_coord(ndim,iplotx,iploty) result(iplotz) |
| 245 |
integer, intent(in) :: ndim,iplotx,iploty |
| 246 |
integer :: i |
| 247 |
|
| 248 |
i = get_z_dir(ndim,iplotx,iploty) |
| 249 |
iplotz = i - ix(1) + 1 |
| 250 |
if (iplotz < 0) iplotz = 1 |
| 251 |
if (iplotz > ndim) iplotz = ndim |
| 252 |
|
| 253 |
end function get_z_coord |
| 254 |
|
| 255 |
!----------------------------------------------------------------- |
| 256 |
! |
| 257 |
! utility to strip the units label from a label string |
| 258 |
! |
| 259 |
!----------------------------------------------------------------- |
| 260 |
elemental function strip_units(string,unitslab) |
| 261 |
character(len=lenlabel), intent(in) :: string |
| 262 |
character(len=*), intent(in) :: unitslab |
| 263 |
character(len=lenlabel) :: strip_units |
| 264 |
integer :: ipos |
| 265 |
|
| 266 |
strip_units = string |
| 267 |
if (len_trim(unitslab) > 0) then |
| 268 |
!--remove units label (only do this once) |
| 269 |
ipos = index(trim(strip_units),trim(unitslab)) |
| 270 |
if (ipos /= 0) then |
| 271 |
strip_units = strip_units(1:ipos-1)//& |
| 272 |
strip_units(ipos+len_trim(unitslab)+1:len_trim(strip_units)) |
| 273 |
endif |
| 274 |
endif |
| 275 |
|
| 276 |
end function strip_units |
| 277 |
|
| 278 |
!----------------------------------------------------------------- |
| 279 |
! |
| 280 |
! utility to strip spaces, escape sequences and |
| 281 |
! units labels from strings (this can be called for both |
| 282 |
! function strings and variable labels) |
| 283 |
! |
| 284 |
!----------------------------------------------------------------- |
| 285 |
elemental function shortstring(string,unitslab) |
| 286 |
use asciiutils, only:string_delete |
| 287 |
character(len=lenlabel), intent(in) :: string |
| 288 |
character(len=*), intent(in), optional :: unitslab |
| 289 |
character(len=lenlabel) :: shortstring |
| 290 |
|
| 291 |
shortstring = string |
| 292 |
!--strip off the units label |
| 293 |
if (present(unitslab)) shortstring = strip_units(shortstring,unitslab) |
| 294 |
|
| 295 |
!--remove spaces |
| 296 |
call string_delete(shortstring,' ') |
| 297 |
!--remove escape sequences (\d etc.) |
| 298 |
call string_delete(shortstring,'\d') |
| 299 |
call string_delete(shortstring,'\u') |
| 300 |
call string_delete(shortstring,'\g') |
| 301 |
call string_delete(shortstring,'\') |
| 302 |
call string_delete(shortstring,'_') |
| 303 |
|
| 304 |
end function shortstring |
| 305 |
|
| 306 |
!------------------------------------------------------------------ |
| 307 |
! |
| 308 |
! Same as shortstring, but also strips any arithmetic operators |
| 309 |
! should be applied to variable names, but not function strings |
| 310 |
! |
| 311 |
!----------------------------------------------------------------- |
| 312 |
elemental function shortlabel(string,unitslab,lc) |
| 313 |
use asciiutils, only:string_delete,lcase |
| 314 |
character(len=lenlabel), intent(in) :: string |
| 315 |
character(len=*), intent(in), optional :: unitslab |
| 316 |
character(len=lenlabel) :: shortlabel |
| 317 |
logical, intent(in), optional :: lc |
| 318 |
|
| 319 |
if (present(unitslab)) then |
| 320 |
shortlabel = shortstring(string,unitslab) |
| 321 |
else |
| 322 |
shortlabel = shortstring(string) |
| 323 |
endif |
| 324 |
!--remove arithmetic operators from labels |
| 325 |
call string_delete(shortlabel,'**') |
| 326 |
call string_delete(shortlabel,'/') |
| 327 |
call string_delete(shortlabel,'*') |
| 328 |
call string_delete(shortlabel,'+') |
| 329 |
call string_delete(shortlabel,'-') |
| 330 |
call string_delete(shortlabel,'^') |
| 331 |
call string_delete(shortlabel,'sqrt(') |
| 332 |
call string_delete(shortlabel,'(') |
| 333 |
call string_delete(shortlabel,')') |
| 334 |
call string_delete(shortlabel,'{') |
| 335 |
call string_delete(shortlabel,'}') |
| 336 |
call string_delete(shortlabel,'[') |
| 337 |
call string_delete(shortlabel,']') |
| 338 |
call string_delete(shortlabel,'<') |
| 339 |
call string_delete(shortlabel,'>') |
| 340 |
call string_delete(shortlabel,'\(2268)') |
| 341 |
|
| 342 |
if (present(lc)) then |
| 343 |
if (lc) shortlabel = lcase(shortlabel) |
| 344 |
endif |
| 345 |
|
| 346 |
end function shortlabel |
| 347 |
|
| 348 |
!--------------------------------------------------------------- |
| 349 |
! interface for adjusting the label for column-integrated plots |
| 350 |
!--------------------------------------------------------------- |
| 351 |
function integrate_label(labelin,iplot,izcol,normalise,iRescale,labelzint,& |
| 352 |
projlabelformat,iapplyprojformat) |
| 353 |
use asciiutils, only:string_replace,string_delete |
| 354 |
character(len=*), intent(in) :: labelin,labelzint,projlabelformat |
| 355 |
integer, intent(in) :: iplot,izcol,iapplyprojformat |
| 356 |
logical, intent(in) :: normalise,iRescale |
| 357 |
character(len=len(label)+20) :: integrate_label |
| 358 |
|
| 359 |
if (len_trim(projlabelformat) /= 0 .and. (iapplyprojformat==0 .or. iapplyprojformat==iplot)) then |
| 360 |
integrate_label = projlabelformat |
| 361 |
call string_replace(integrate_label,'%l',trim(labelin)) |
| 362 |
if (iRescale) then |
| 363 |
call string_replace(integrate_label,'%z',trim(label(izcol)(1:index(label(izcol),unitslabel(izcol))-1))) |
| 364 |
call string_replace(integrate_label,'%uz',trim(unitslabel(izcol))) |
| 365 |
else |
| 366 |
call string_replace(integrate_label,'%z',trim(label(izcol))) |
| 367 |
endif |
| 368 |
else |
| 369 |
if (normalise) then |
| 370 |
integrate_label = '< '//trim(labelin)//' >' |
| 371 |
else |
| 372 |
if (iRescale) then |
| 373 |
! use composite units label e.g. \int rho_d [g/cm^3 pc] |
| 374 |
integrate_label = '\int '// & |
| 375 |
trim(labelin(1:index(labelin,unitslabel(iplot))-1))//' d'// & |
| 376 |
trim(label(izcol)(1:index(label(izcol),unitslabel(izcol))-1))// & |
| 377 |
get_unitlabel_coldens(iRescale,labelzint,unitslabel(iplot)) |
| 378 |
! use mix of units labels \int rho_d [g/cm^3] dz [pc] |
| 379 |
!integrate_label = '\int '//trim(labelin)//' d'// & |
| 380 |
! trim(label(izcol)(1:index(label(izcol),unitslabel(izcol))-1))//trim(labelzint) |
| 381 |
else |
| 382 |
integrate_label = '\int '//trim(labelin)//' d'//trim(shortlabel(label(izcol),unitslabel(izcol))) |
| 383 |
endif |
| 384 |
if (index(labelin,'\rho_{d,') > 0) then |
| 385 |
integrate_label = labelin(1:index(labelin,unitslabel(iplot))-1) |
| 386 |
call string_delete(integrate_label,'\rho_{d,') |
| 387 |
call string_delete(integrate_label,'}') |
| 388 |
integrate_label = trim(integrate_label)//' dust surface density' |
| 389 |
integrate_label = trim(integrate_label)//get_unitlabel_coldens(iRescale,labelzint,unitslabel(iplot)) |
| 390 |
endif |
| 391 |
if (iplot==irho .and. (index(labelin,'density') /= 0 .or. index(labelin,'rho') /= 0)) then |
| 392 |
integrate_label = 'column density' |
| 393 |
integrate_label = trim(integrate_label)//get_unitlabel_coldens(iRescale,labelzint,unitslabel(irho)) |
| 394 |
endif |
| 395 |
endif |
| 396 |
endif |
| 397 |
end function integrate_label |
| 398 |
|
| 399 |
!----------------------------------------------------------------- |
| 400 |
! |
| 401 |
! utility to convert the units label to g/cm^2 where appropriate |
| 402 |
! would be nice to have a more robust way of knowing what the units mean |
| 403 |
! |
| 404 |
!----------------------------------------------------------------- |
| 405 |
function get_unitlabel_coldens(iRescale,labelzint,unitlabel) |
| 406 |
use asciiutils, only:string_delete,string_replace |
| 407 |
logical, intent(in) :: iRescale |
| 408 |
character(len=*), intent(in) :: labelzint,unitlabel |
| 409 |
character(len=lenunitslabel) :: get_unitlabel_coldens |
| 410 |
|
| 411 |
if (iRescale .and. len_trim(labelzint) > 0) then |
| 412 |
get_unitlabel_coldens = trim(unitlabel)//trim(labelzint) |
| 413 |
call string_delete(get_unitlabel_coldens,']') |
| 414 |
call string_delete(get_unitlabel_coldens,'[') |
| 415 |
get_unitlabel_coldens = ' ['//trim(adjustl(get_unitlabel_coldens))//']' |
| 416 |
call string_replace(get_unitlabel_coldens,'/cm\u3\d cm','/cm^2') |
| 417 |
call string_replace(get_unitlabel_coldens,'/cm^3 cm','/cm^2') |
| 418 |
else |
| 419 |
get_unitlabel_coldens = ' ' |
| 420 |
endif |
| 421 |
|
| 422 |
end function get_unitlabel_coldens |
| 423 |
|
| 424 |
!----------------------------------------------------------------- |
| 425 |
! |
| 426 |
! utility to "guess" which particle type contains sink particles |
| 427 |
! from the label |
| 428 |
! |
| 429 |
!----------------------------------------------------------------- |
| 430 |
integer function get_sink_type(ntypes) |
| 431 |
integer, intent(in) :: ntypes |
| 432 |
integer :: i |
| 433 |
|
| 434 |
get_sink_type = 0 |
| 435 |
do i=1,ntypes |
| 436 |
if (get_sink_type==0 .and. index(labeltype(i),'sink') /= 0) get_sink_type = i |
| 437 |
if (get_sink_type==0 .and. index(labeltype(i),'compact object') /= 0) get_sink_type = i |
| 438 |
if (get_sink_type==0 .and. index(labeltype(i),'point mass') /= 0) get_sink_type = i |
| 439 |
enddo |
| 440 |
|
| 441 |
end function get_sink_type |
| 442 |
|
| 443 |
!----------------------------------------------------------------- |
| 444 |
! |
| 445 |
! utility to neatly print number of particles by type |
| 446 |
! |
| 447 |
!----------------------------------------------------------------- |
| 448 |
subroutine print_types(noftype,ltype) |
| 449 |
integer, dimension(:), intent(in) :: noftype |
| 450 |
character(len=*), dimension(:), intent(in) :: ltype |
| 451 |
integer :: itype,n,i |
| 452 |
character(len=1) :: sp |
| 453 |
|
| 454 |
i = 0 |
| 455 |
sp = ' ' |
| 456 |
do itype=1,size(noftype) |
| 457 |
n = noftype(itype) |
| 458 |
if (n > 0) then |
| 459 |
i = i + 1 |
| 460 |
if (i > 1) sp = ',' |
| 461 |
if (n < 10000) then |
| 462 |
write(*,"(a,i4)",advance='no') trim(sp)//' n('//trim(ltype(itype))//') = ',n |
| 463 |
elseif (n < 1000000) then |
| 464 |
write(*,"(a,i6)",advance='no') trim(sp)//' n('//trim(ltype(itype))//') = ',n |
| 465 |
elseif (n < 100000000) then |
| 466 |
write(*,"(a,i8)",advance='no') trim(sp)//' n('//trim(ltype(itype))//') = ',n |
| 467 |
else |
| 468 |
write(*,"(a,i10)",advance='no') trim(sp)//' n('//trim(ltype(itype))//') = ',n |
| 469 |
endif |
| 470 |
endif |
| 471 |
enddo |
| 472 |
write(*,*) |
| 473 |
|
| 474 |
end subroutine print_types |
| 475 |
|
| 476 |
!----------------------------------------------------------------- |
| 477 |
! |
| 478 |
! utility to make labels for vector quantities |
| 479 |
! these change depending on the coordinate system |
| 480 |
! e.g. v_x, v_y, v_z; B_x, B_y, B_z |
| 481 |
! |
| 482 |
!----------------------------------------------------------------- |
| 483 |
subroutine make_vector_label(lvec,ivec,nvec,iamveci,labelveci,labeli,labelx) |
| 484 |
character(len=*), intent(in) :: lvec |
| 485 |
integer, intent(in) :: ivec,nvec |
| 486 |
integer, intent(inout) :: iamveci(:) |
| 487 |
character(len=*), intent(inout) :: labelveci(:),labeli(:) |
| 488 |
character(len=*), intent(in) :: labelx(3) |
| 489 |
integer :: i |
| 490 |
character(len=len(lvec)) :: tmplvec |
| 491 |
|
| 492 |
tmplvec = lvec |
| 493 |
if (ivec > 0 .and. ivec+nvec <= size(labeli)) then |
| 494 |
iamveci(ivec:ivec+nvec-1) = ivec |
| 495 |
labelveci(ivec:ivec+nvec-1) = tmplvec |
| 496 |
do i=1,nvec |
| 497 |
labeli(ivec+i-1) = trim(tmplvec)//'_'//labelx(i) |
| 498 |
enddo |
| 499 |
endif |
| 500 |
|
| 501 |
end subroutine make_vector_label |
| 502 |
|
| 503 |
!----------------------------------------------------------------- |
| 504 |
! |
| 505 |
! utility to neatly format a grain size for use in plot label |
| 506 |
! |
| 507 |
!----------------------------------------------------------------- |
| 508 |
function get_label_grain_size(sizecm) result(string) |
| 509 |
use asciiutils, only:string_delete |
| 510 |
real, intent(in) :: sizecm |
| 511 |
character(len=16) :: string |
| 512 |
character(len=6) :: ulab |
| 513 |
|
| 514 |
if (sizecm >= 1000.) then |
| 515 |
write(string,"(1pg10.3)") sizecm*1.e-5 |
| 516 |
ulab = 'km' |
| 517 |
elseif (sizecm >= 100.) then |
| 518 |
write(string,"(1pg10.3)") sizecm*0.01 |
| 519 |
ulab = 'm' |
| 520 |
elseif (sizecm >= 1.) then |
| 521 |
write(string,"(1pg10.3)") sizecm |
| 522 |
ulab = 'cm' |
| 523 |
elseif (sizecm >= 0.09) then |
| 524 |
write(string,"(1pg10.3)") sizecm*10. |
| 525 |
ulab = 'mm' |
| 526 |
elseif (sizecm >= 1.e-4) then |
| 527 |
write(string,"(1pg10.3)") sizecm*1.e4 |
| 528 |
ulab = '\gmm' |
| 529 |
elseif (sizecm >= 1.e-7) then |
| 530 |
write(string,"(1pg10.3)") sizecm*1.e7 |
| 531 |
ulab = 'nm' |
| 532 |
else |
| 533 |
write(string,"(1pg10.3)") sizecm |
| 534 |
ulab = 'cm' |
| 535 |
endif |
| 536 |
string = adjustl(string) |
| 537 |
call string_delete(string,'.000 ') |
| 538 |
call string_delete(string,'.00 ') |
| 539 |
call string_delete(string,'.0 ') |
| 540 |
call string_delete(string,'. ') |
| 541 |
string = trim(string)//trim(ulab) |
| 542 |
|
| 543 |
end function get_label_grain_size |
| 544 |
|
| 545 |
!----------------------------------------------------------------- |
| 546 |
! |
| 547 |
! save the list of labels that are actually used for plotting |
| 548 |
! |
| 549 |
!----------------------------------------------------------------- |
| 550 |
subroutine set_required_labels(required) |
| 551 |
logical, intent(in) :: required(0:) |
| 552 |
integer :: icol |
| 553 |
|
| 554 |
! save original list of labels |
| 555 |
labelorig = label |
| 556 |
|
| 557 |
nreq = 0 |
| 558 |
labelreq = '' |
| 559 |
do icol=1,size(required)-1 |
| 560 |
nreq = nreq + 1 |
| 561 |
if (required(icol)) then |
| 562 |
labelreq(icol) = shortlabel(label(icol),unitslabel(icol)) |
| 563 |
endif |
| 564 |
enddo |
| 565 |
|
| 566 |
!print*,'DEBUG: required labels:' |
| 567 |
!do icol=1,nreq |
| 568 |
! if (len_trim(labelreq(icol)) > 0) print*,trim(labelreq(icol)) |
| 569 |
!enddo |
| 570 |
|
| 571 |
end subroutine set_required_labels |
| 572 |
|
| 573 |
!----------------------------------------------------------------- |
| 574 |
! |
| 575 |
! see if a column has shifted in the actual data |
| 576 |
! |
| 577 |
!----------------------------------------------------------------- |
| 578 |
integer function check_for_shifted_column(icol,labelnew) result(inew) |
| 579 |
use asciiutils, only:match_tag |
| 580 |
integer, intent(in) :: icol |
| 581 |
character(len=*), intent(out), optional :: labelnew |
| 582 |
character(len=lenlabel) :: labelcol |
| 583 |
|
| 584 |
inew = icol |
| 585 |
labelcol = shortlabel(label(icol),unitslabel(icol)) |
| 586 |
|
| 587 |
if (trim(labelcol) /= trim(labelreq(icol)) .and. len_trim(labelreq(icol)) > 0) then |
| 588 |
if (.not.present(labelnew)) write(*,"(1x,a,i3,a)",advance='no') 'column ',icol,' has shifted: was '//& |
| 589 |
trim(labelreq(icol))//' but got '//trim(labelcol) |
| 590 |
inew = match_tag(shortlabel(label(1:maxplot),unitslabel(1:maxplot)),labelreq(icol)) |
| 591 |
if (inew > 0) then |
| 592 |
if (present(labelnew)) then |
| 593 |
labelnew = trim(shortlabel(label(inew),unitslabel(inew)))//trim(unitslabel(icol)) |
| 594 |
else |
| 595 |
print "(1x,a,i3)",': found '//trim(shortlabel(label(inew),unitslabel(inew)))//' in col ',inew |
| 596 |
endif |
| 597 |
else |
| 598 |
inew = icol |
| 599 |
endif |
| 600 |
endif |
| 601 |
|
| 602 |
end function check_for_shifted_column |
| 603 |
|
| 604 |
!----------------------------------------------------------------- |
| 605 |
! |
| 606 |
! compute the backwards map from inew -> icol based on where |
| 607 |
! a column has been shifted to. This enables lookup of original |
| 608 |
! units etc which can be used to scale the data |
| 609 |
! |
| 610 |
!----------------------------------------------------------------- |
| 611 |
function map_shifted_columns() result(imap) |
| 612 |
integer :: imap(maxplot) |
| 613 |
integer :: i,icol |
| 614 |
|
| 615 |
do i=1,size(imap) |
| 616 |
imap(i) = i |
| 617 |
enddo |
| 618 |
|
| 619 |
do i=1,size(imap) |
| 620 |
icol = i |
| 621 |
if (len_trim(label(i)) > 0) icol = check_for_shifted_column(i) |
| 622 |
if (icol /= i .and. icol > 0) then |
| 623 |
!print*,i,' setting imap=',icol |
| 624 |
imap(icol) = i |
| 625 |
endif |
| 626 |
enddo |
| 627 |
|
| 628 |
end function map_shifted_columns |
| 629 |
|
| 630 |
!----------------------------------------------------------------- |
| 631 |
! |
| 632 |
! set labels for columns which have been tagged as vectors |
| 633 |
! using the iamvec label |
| 634 |
! |
| 635 |
!----------------------------------------------------------------- |
| 636 |
subroutine set_vector_labels(ncolumns,ndimV,iamveci,labelveci,labeli,labelcoordi) |
| 637 |
integer, intent(in) :: ncolumns,ndimV |
| 638 |
integer, intent(inout) :: iamveci(:) |
| 639 |
character(len=*), intent(in) :: labelcoordi(:) |
| 640 |
character(len=lenlabel), intent(inout) :: labelveci(:),labeli(:) |
| 641 |
character(len=lenlabel) :: tmplabel |
| 642 |
integer :: i |
| 643 |
! |
| 644 |
!--set labels for vector quantities |
| 645 |
! |
| 646 |
i = 1 |
| 647 |
do while (i <= ncolumns) |
| 648 |
if (iamvec(i) > 0) then |
| 649 |
tmplabel = labeli(i) |
| 650 |
call make_vector_label(tmplabel,i,ndimV,iamveci,labelveci,labeli,labelcoordi) |
| 651 |
i = i + ndimV |
| 652 |
else |
| 653 |
i = i + 1 |
| 654 |
endif |
| 655 |
enddo |
| 656 |
|
| 657 |
end subroutine set_vector_labels |
| 658 |
|
| 659 |
end module labels |