Skip to content

Commit 69645bf

Browse files
committed
added optional name output to get_finite_diff_formula
1 parent d4536b5 commit 69645bf

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/numerical_differentiation_module.f90

+4-1
Original file line numberDiff line numberDiff line change
@@ -482,21 +482,24 @@ end subroutine get_formula
482482
!###See also:
483483
! * [[get_formula]]
484484

485-
subroutine get_finite_diff_formula(id,formula)
485+
subroutine get_finite_diff_formula(id,formula,name)
486486

487487
implicit none
488488

489489
integer,intent(in) :: id !! the id code for the method
490490
character(len=:),allocatable,intent(out) :: formula !! the formula string
491+
character(len=:),allocatable,intent(out),optional :: name
491492

492493
type(finite_diff_method) :: fd
493494
logical :: found
494495

495496
call get_finite_difference_method(id,fd,found)
496497
if (found .and. fd%id/=0) then
497498
call get_formula(fd,formula)
499+
if (present(name)) name = fd%name
498500
else
499501
formula = ''
502+
if (present(name)) name = ''
500503
end if
501504

502505
end subroutine get_finite_diff_formula

tests/test2.f90

+4-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ program test2
4545
real(wp),dimension(:),allocatable :: results_dpert !! results array - dpert
4646
real(wp),dimension(:),allocatable :: results_errors !! results array - errors
4747
type(pyplot) :: plt !! for plotting the results
48-
character(len=:),allocatable :: formula !! finite diff forumla for the plot legend
48+
character(len=:),allocatable :: formula !! finite diff formula for the plot legend
49+
character(len=:),allocatable :: name !! finite diff name for the plot legend
4950
integer :: idx !! index in results arrays
5051
character(len=:),allocatable :: real_kind_str !! real kind for the plot title
5152
real(wp),dimension(3) :: color !! line color array
@@ -83,7 +84,7 @@ program test2
8384

8485
idx = 0
8586
i = methods(j) ! method id
86-
call get_finite_diff_formula(i,formula)
87+
call get_finite_diff_formula(i,formula,name)
8788

8889
! cycle through perturbation step sizes:
8990
do ipert = exp_star*exp_scale, exp_stop*exp_scale, exp_step
@@ -135,7 +136,7 @@ program test2
135136
! plot for this method:
136137
call plt%add_plot(results_dpert,results_errors,&
137138
xscale='log', yscale='log',&
138-
label=formula,linestyle='.-',markersize=5,linewidth=2, &
139+
label = formula,linestyle='.-',markersize=5,linewidth=2, &
139140
color = color,&
140141
xlim = ylim,&
141142
ylim = ylim)

0 commit comments

Comments
 (0)