This subroutine plots the basis functions or their th order derivatives having index from first
to last
by computing at interpolation points defined by plotRes
, and print the image file into "|cwd|
/data/work
/fname
.ext" if the workspace work
is presented, "|cwd|
/data/img/fname
.ext" if else. Plotting requires GNUPlot installed on your computer. The input parameter terminal
set the output terminal of GNUPlot.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(basis), | intent(in) | :: | me | |||
integer, | intent(in), | optional | :: | first | First index to be plotted |
|
integer, | intent(in), | optional | :: | last | Last index to be plotted |
|
integer, | intent(in), | optional | :: | d | Derivatives degree |
|
integer, | intent(in), | optional | :: | plotRes | Resolution of the calculation, Default = 100 |
|
character(len=*), | intent(in), | optional | :: | title | Title of the graph, Default = "Basis functions" |
|
character(len=*), | intent(in), | optional | :: | work | Current work name to create folder |
|
character(len=*), | intent(in), | optional | :: | fname | Filename of the *.png output, if GNUPlot terminal is |
|
character(len=*), | intent(in), | optional | :: | terminal | GNUPlot terminal, Default = |
|
logical, | intent(in), | optional | :: | showPlot | Key to open created |
subroutine PlotBasisFunc(me,first,last,d,plotRes,title,work,fname,terminal,showPlot)
! Variables
class(basis), intent(in) :: me
integer, intent(in), optional :: first !< First index to be plotted
integer, intent(in), optional :: last !< Last index to be plotted
integer, intent(in), optional :: d !< Derivatives degree
integer, intent(in), optional :: plotRes !< Resolution of the calculation, Default = 100
character(*), intent(in), optional :: title !< Title of the graph, Default = "Basis functions"
character(*), intent(in), optional :: work !< Current work name to create folder
character(*), intent(in), optional :: fname !< Filename of the \*.png output, if *GNUPlot* terminal is `png`. Default = "BasisFunctions"
character(*), intent(in), optional :: terminal !< *GNUPlot* terminal, Default = ` wxt `
logical, intent(in), optional :: showPlot !< Key to open created ` png ` files
!locals
integer :: i, j, k, m, r, f, l, dd, iunit
character(200) :: fn, ptitle, fmt1, fmt2, yaxis
character(1024) :: pl
real(wp) ::du, u
real(wp), allocatable :: array(:), bf(:,:)
logical :: openfile
type(gpf):: gp
!set gnuplot terminal
!if(present(terminal)) gp%term_type=trim(terminal)
openfile = .false. ; if(present(showPlot)) openfile = showPlot
r = 100; if(present(plotRes)) r=plotRes
f = 0; if(present(first)) f=first
l = me%n; if(present(last)) l=last
dd = 0; if(present(d)) dd=d
allocate(bf(0:me%p,0:dd))
allocate(array(0:l-f))
write(fn, '("_p",i0,"_d",i0,"_idx",i0,"_to_",i0)') me%p,dd,f,l
if(present(fname)) then
fn = fname // trim(fn)
else
fn = "BasisFunctions" // trim(fn)
end if
if(present(work)) then
call gp%setoutput(folder="data/"//trim(work)//"/img/", fname=fn, term=terminal)
else
call gp%setoutput(folder="data/img/", fname=fn, term=terminal)
end if
!set plot title
ptitle = "Basis functions"; if(present(title)) ptitle=title
call gp%title(trim(ptitle))
!set headers format
write(fmt1,'(a,i2.1,a)') '("x-values",', l-f+1, '(1x,"N_{",i0,"}"))'
!set data format
write(fmt2,'(a,i2.1,a)') '(', l-f+2, '(2x,e23.15E3))'
open(newunit=iunit,file='data.txt')
!write headers
write(iunit,trim(fmt1)) (j,j=f,l)
!calculation and writing data
du = ( me%kv(me%m) - me%kv(0) ) / r
do i=0,r
u = i * du
k = me%FindSpan(u)
call me%DersBasisFuns(u,dd,bf,k)
array = 0.0_wp; m = 0
do j=f,l
if(k-me%p <= j .and. j <= k)then
array(j) = bf(m,dd)
m = m+1
end if
end do
write(iunit,fmt2) u, (array(j),j=f,l)
end do
call gp%xlabel('u')
if(dd>0)then
write(yaxis,'("N_{i}^{(",i0,")}(u)")') dd
else
yaxis = "N_{i}(u)"
end if
call gp%add_script('set ylabel "'//trim(yaxis)//'" rotate by 0')
call gp%add_script('set tics')
call gp%add_script('set colorsequence podo')
!set plotting script
write(pl,'("plot for [i=2:",i0,"] ",a," using 1:i w lines t columnheader(i) lw 2.5")') l-f+2, '"data.txt"'
call gp%add_script(pl)
call gp%run_script()
call gp%reset()
if(present(terminal) .and. openfile) then
if(trim(terminal)=="png") then
call execute_command_line(trim(gp%fullpath))
end if
end if
close(iunit,status='delete')
end subroutine PlotBasisFunc