1+ program example
2+ use iso_fortran_env
3+ use fstats
4+ use fplot_core
5+ implicit none
6+
7+ ! Parameters
8+ integer (int32), parameter :: n = 9
9+ integer (int32), parameter :: m = 100
10+
11+ ! Local Variables
12+ type (spline_interpolator) :: interp
13+ real (real64) :: x(n), y(n), xi(m), yi1(m), yi2(m)
14+
15+ ! Plot Variables
16+ type (plot_2d) :: plt
17+ type (plot_data_2d) :: pd1, pd2, pd3
18+ class(legend), pointer :: lgnd
19+
20+ ! Initialization
21+ x = [- 4.0d0 , - 3.0d0 , - 2.0d0 , - 1.0d0 , 0.0d0 , 1.0d0 , 2.0d0 , 3.0d0 , 4.0d0 ]
22+ y = [0.0d0 , 0.15d0 , 1.12d0 , 2.36d0 , 2.36d0 , 1.46d0 , 0.49d0 , 0.06d0 , &
23+ 0.0d0 ]
24+ xi = linspace(minval (x), maxval (x), m)
25+
26+ ! Interpolation - Default
27+ call interp% initialize(x, y)
28+ call interp% interpolate(xi, yi1)
29+
30+ ! Interpolation - defined slope at both ends
31+ call interp% initialize(x, y, &
32+ ibcbeg = SPLINE_KNOWN_FIRST_DERIVATIVE, ybcbeg = 0.0d0 , &
33+ ibcend = SPLINE_KNOWN_FIRST_DERIVATIVE, ybcend = 0.0d0 )
34+ call interp% interpolate(xi, yi2)
35+
36+ ! Plot the results
37+ call plt% initialize()
38+ lgnd = > plt% get_legend()
39+ call lgnd% set_is_visible(.true. )
40+
41+ call pd1% define_data(x, y)
42+ call pd1% set_name(" Data" )
43+ call pd1% set_draw_line(.false. )
44+ call pd1% set_draw_markers(.true. )
45+ call pd1% set_marker_style(MARKER_X)
46+ call pd1% set_marker_scaling(2.0 )
47+ call pd1% set_line_width(2.0 )
48+ call pd1% set_line_color(CLR_BLACK)
49+ call plt% push(pd1)
50+
51+ call pd2% define_data(xi, yi1)
52+ call pd2% set_name(" Default" )
53+ call pd2% set_line_width(2.0 )
54+ call pd2% set_line_color(CLR_RED)
55+ call plt% push(pd2)
56+
57+ call pd3% define_data(xi, yi2)
58+ call pd3% set_name(" Enforced End Slope" )
59+ call pd3% set_line_style(LINE_DASHED)
60+ call pd3% set_line_width(2.0 )
61+ call pd3% set_line_color(CLR_BLUE)
62+ call plt% push(pd3)
63+
64+ call plt% draw()
65+ end program
0 commit comments