| 1 |
!----------------------------------------------------------------- |
| 2 |
! |
| 3 |
! This file is (or was) part of SPLASH, a visualisation tool |
| 4 |
! for Smoothed Particle Hydrodynamics written by Daniel Price: |
| 5 |
! |
| 6 |
! http://users.monash.edu.au/~dprice/splash |
| 7 |
! |
| 8 |
! SPLASH comes with ABSOLUTELY NO WARRANTY. |
| 9 |
! This is free software; and you are welcome to redistribute |
| 10 |
! it under the terms of the GNU General Public License |
| 11 |
! (see LICENSE file for details) and the provision that |
| 12 |
! this notice remains intact. If you modify this file, please |
| 13 |
! note section 2a) of the GPLv2 states that: |
| 14 |
! |
| 15 |
! a) You must cause the modified files to carry prominent notices |
| 16 |
! stating that you changed the files and the date of any change. |
| 17 |
! |
| 18 |
! Copyright (C) 2005-2009 Daniel Price. All rights reserved. |
| 19 |
! Contact: [email protected] |
| 20 |
! |
| 21 |
!----------------------------------------------------------------- |
| 22 |
|
| 23 |
!--------------------------------------------------------------------------- |
| 24 |
! module containing application programming interfaces for basic |
| 25 |
! plotting functions. The idea is to add more to this module to |
| 26 |
! eventually use it to be able to change backends more easily. |
| 27 |
!--------------------------------------------------------------------------- |
| 28 |
module plotutils |
| 29 |
use plotlib, only:plot_line,plot_bins |
| 30 |
implicit none |
| 31 |
public :: plotline,plotbins,formatreal |
| 32 |
|
| 33 |
private |
| 34 |
|
| 35 |
contains |
| 36 |
|
| 37 |
! |
| 38 |
! line plotting, with blanking |
| 39 |
! |
| 40 |
subroutine plotline(npts,xline,yline,blank) |
| 41 |
integer, intent(in) :: npts |
| 42 |
real, intent(in), dimension(:) :: xline,yline |
| 43 |
real, intent(in), optional :: blank |
| 44 |
integer :: i,nseg,istart |
| 45 |
|
| 46 |
if (present(blank)) then |
| 47 |
nseg = 0 |
| 48 |
istart = 1 |
| 49 |
!--plot line in segments, leaving blank segments where y=blank |
| 50 |
do i=1,npts |
| 51 |
if (abs(yline(i)-blank) < tiny(yline) .or. i==npts) then |
| 52 |
if (nseg > 0) call plot_line(nseg,xline(istart:istart+nseg),yline(istart:istart+nseg)) |
| 53 |
istart = i+1 |
| 54 |
nseg = 0 |
| 55 |
else |
| 56 |
nseg = min(nseg + 1,npts-1) |
| 57 |
endif |
| 58 |
enddo |
| 59 |
else |
| 60 |
call plot_line(npts,xline,yline) |
| 61 |
endif |
| 62 |
|
| 63 |
return |
| 64 |
end subroutine plotline |
| 65 |
|
| 66 |
! |
| 67 |
! binned histogram plotting, with blanking |
| 68 |
! |
| 69 |
subroutine plotbins(nbins,xbins,ybins,blank) |
| 70 |
integer, intent(in) :: nbins |
| 71 |
real, intent(in), dimension(:) :: xbins,ybins |
| 72 |
real, intent(in), optional :: blank |
| 73 |
integer :: i,nseg,istart |
| 74 |
|
| 75 |
if (present(blank)) then |
| 76 |
nseg = 0 |
| 77 |
istart = 1 |
| 78 |
!--plot line in segments, leaving blank segments where y=blank |
| 79 |
do i=1,nbins |
| 80 |
if (abs(ybins(i)-blank) < tiny(ybins) .or. i==nbins) then |
| 81 |
if (nseg > 0) call plot_bins(nseg,xbins(istart:istart+nseg),ybins(istart:istart+nseg),.true.) |
| 82 |
istart = i+1 |
| 83 |
nseg = 0 |
| 84 |
else |
| 85 |
nseg = min(nseg + 1,nbins-1) |
| 86 |
endif |
| 87 |
enddo |
| 88 |
else |
| 89 |
call plot_bins(nbins,xbins,ybins,.true.) |
| 90 |
endif |
| 91 |
|
| 92 |
return |
| 93 |
end subroutine plotbins |
| 94 |
|
| 95 |
! |
| 96 |
! formatting of real variables into strings (like PGNUMB) |
| 97 |
! |
| 98 |
subroutine formatreal(val,string,ierror) |
| 99 |
real, intent(in) :: val |
| 100 |
character(len=*), intent(out) :: string |
| 101 |
integer, intent(out), optional :: ierror |
| 102 |
integer :: ierr,i,idot |
| 103 |
logical :: nonzero |
| 104 |
|
| 105 |
if (abs(val) >= 1.d99) then |
| 106 |
write(string,"(1pe10.3)",iostat=ierr) val |
| 107 |
elseif (abs(val) < 1.e-3 .or. abs(val) >= 1.e4) then |
| 108 |
write(string,"(1pe9.2)",iostat=ierr) val |
| 109 |
elseif (abs(val) < 0.1) then |
| 110 |
write(string,"(f8.3)",iostat=ierr) val |
| 111 |
elseif (abs(val) >= 100.) then |
| 112 |
write(string,"(f8.0)",iostat=ierr) val |
| 113 |
else |
| 114 |
write(string,"(f8.2)",iostat=ierr) val |
| 115 |
endif |
| 116 |
string = adjustl(trim(string)) |
| 117 |
|
| 118 |
if (present(ierror)) ierror = ierr |
| 119 |
|
| 120 |
! |
| 121 |
!--strip trailing zeros after the decimal place |
| 122 |
! (and the decimal place if it is the last character) |
| 123 |
! |
| 124 |
idot = index(string,'.') |
| 125 |
if (idot > 0) then |
| 126 |
nonzero = .false. |
| 127 |
do i = len_trim(string),idot,-1 |
| 128 |
if (.not.nonzero .and. string(i:i)=='0') then |
| 129 |
string(i:i) = ' ' |
| 130 |
elseif (.not.nonzero .and. string(i:i)=='.') then |
| 131 |
string(i:i) = ' ' |
| 132 |
nonzero = .true. |
| 133 |
else |
| 134 |
nonzero = .true. |
| 135 |
endif |
| 136 |
enddo |
| 137 |
endif |
| 138 |
string = trim(string) |
| 139 |
|
| 140 |
return |
| 141 |
end subroutine formatreal |
| 142 |
|
| 143 |
end module plotutils |