diff --git a/.gitignore b/.gitignore index b0b6e90..0536f47 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,23 @@ +# Build files **/*.mod +# FORD files doc/ +# RAW debugging fort.* -**/*.gp \ No newline at end of file +# OGPF output script files +**/*.gp +# PyPlot allowed output files +**/*.eps +**/*.jpeg +**/*.jpg +**/*.pdf +**/*.pgf +**/*.png +**/*.ps +**/*.raw +**/*.rgba +**/*.svg +**/*.svgz +**/*.tif +**/*.tiff +**/*.py \ No newline at end of file diff --git a/fpm.toml b/fpm.toml index 7fa81fe..a1bcd09 100644 --- a/fpm.toml +++ b/fpm.toml @@ -13,5 +13,7 @@ library = true [dependencies] assert.git = "https://github.com/sourceryinstitute/assert.git" assert.tag = "1.4.0" -ogpf.git = "https://github.com/kookma/ogpf.git" -ogpf.branch = "master" +ogpf.git = "https://github.com/bellomia/OGPF.git" +ogpf.branch = "expose-term-options-to-user" +pyplot-fortran.git = "https://github.com/jacobwilliams/pyplot-fortran.git" +pyplot-fortran.tag = "3.2.0" diff --git a/src/hex_plotter.f90 b/src/hex_plotter.f90 index 2c33ed9..894b242 100644 --- a/src/hex_plotter.f90 +++ b/src/hex_plotter.f90 @@ -1,6 +1,7 @@ module hex_plotter !! Providing plotting facilities for hex tessellations + use pyplot_module use ogpf use hex_coordinates use hex_layout @@ -16,18 +17,27 @@ module hex_plotter contains - subroutine hex_plot(layout,hexagons) + subroutine hex_plot(layout,hexagons,backend,figure_name,script_name,set_terminal) type(unit_cell),intent(in) :: layout type(hex),intent(in) :: hexagons(:) + character(*),intent(in),optional :: backend !! default: "pyplot" (or "gnuplot") + character(*),intent(in),optional :: figure_name + character(*),intent(in),optional :: script_name + character(*),intent(in),optional :: set_terminal !! relevant to gnuplot backend + character(8) :: engine + character(32) :: source_name integer :: M - type(gpf) :: plotter + type(pyplot) :: plt + type(gpf) :: gnu type(xy_tile),allocatable :: corner(:) real(8),dimension(N) :: xtmp,ytmp real(8),allocatable :: x(:),y(:) integer :: i,j + M = size(hexagons) allocate(x(N*M),y(N*M),corner(M)) corner = hex2corner(layout,hexagons) + do i = 1,M do j = 1,N xtmp(j) = corner(i)%vertex(j)%x @@ -36,11 +46,79 @@ subroutine hex_plot(layout,hexagons) x((1+N*(i-1)):N*i) = xtmp y((1+N*(i-1)):N*i) = ytmp enddo - call plotter%xlabel('x') - call plotter%ylabel('y') - call plotter%filename("hex_temp_script.gp") - call plotter%plot(x,y,'with points pt 6 ps 1.2 lc rgb "#000000"') + + if(present(backend))then + engine = trim(backend) + else + engine = "pyplot" + end if + + select case(trim(engine)) + + case default + print*, "unknown backend: no plot generated" + + case ("pyplot") + + call plt%initialize(xlabel='x',ylabel='y',axis_equal=.true.) + call plt%add_plot(x,y,label='',linestyle='o',markersize=5) + + if(present(script_name))then + source_name = script_name + else + source_name = "hex_plot.py" + endif + + if(present(figure_name))then + call plt%savefig(trim(figure_name), pyfile=trim(source_name)) + print* + print*, "> PyPlot figure saved to: "//trim(figure_name) + print* + else + print* + print*, "> PyPlot GUI popping up..." + print* + call plt%showfig(pyfile=trim(source_name)) + endif + + case ("gnuplot") + + if(present(script_name))then + source_name = script_name + else + source_name = "hex_plot.gp" + endif + + if(present(script_name))then + source_name = script_name + else + source_name = "hex_plot.gp" + endif + + if(present(set_terminal))then + call gnu%options("set term "//set_terminal//";") + else + call gnu%options("set term qt;") + endif + + if(present(figure_name))then + call gnu%options('set output "'//figure_name//'"') + endif + + call gnu%options("set size ratio -1;") + call gnu%options("unset grid") + call gnu%xlabel('x') + call gnu%ylabel('y') + call gnu%filename(source_name) + print* + print*, "> Gnuplot GUI popping up..." + print* + call gnu%plot(x,y,'with points pt 6 ps 1.2 lc rgb "#000000"') + + end select + deallocate(x,y) + end subroutine diff --git a/test/unit.f90 b/test/unit.f90 index 1bccb73..5b3b232 100644 --- a/test/unit.f90 +++ b/test/unit.f90 @@ -121,6 +121,10 @@ program unit_test print*, "" print*, "Plotting neighborhood of hex a..." - call hex_plot(v,neighborhood) + call hex_plot(v,neighborhood,backend="pyplot",figure_name='pyflower.svg') + call hex_plot(v,neighborhood,backend="gnuplot",figure_name='gnuflower.svg') + call hex_plot(v,neighborhood,backend="gnuplot",set_terminal='dumb') + call hex_plot(v,neighborhood,backend="pyplot") + ! THIS HAS TO BE TESTED MUCH MORE CAREFULLY TO ASSURE GOOD COVERAGE end program unit_test