Skip to content

Commit

Permalink
Merge pull request #4 from jchristopherson/Development-v1.6.0
Browse files Browse the repository at this point in the history
Development v1.6.0
  • Loading branch information
jchristopherson authored Jun 29, 2021
2 parents 019c0c6 + f15877e commit f1d0a20
Show file tree
Hide file tree
Showing 389 changed files with 32,987 additions and 12,790 deletions.
9 changes: 3 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# CMake project file for FPLOT
cmake_minimum_required(VERSION 3.7)
project(fplot Fortran C)
project(fplot Fortran)

# Define version information
set(FPLOT_MAJOR_VERSION 1)
set(FPLOT_MINOR_VERSION 5)
set(FPLOT_MINOR_VERSION 6)
set(FPLOT_PATCH_VERSION 0)
set(FPLOT_VERSION ${FPLOT_MAJOR_VERSION}.${FPLOT_MINOR_VERSION}.${FPLOT_PATCH_VERSION})

# Locate Dependencies
find_package(ferror 1.3.0)
find_package(fcore 1.0.0)
find_package(fcore 1.1.0)

if (NOT ${ferror_FOUND})
message(STATUS "FERROR not found.")
Expand Down Expand Up @@ -47,9 +47,6 @@ SET(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
# Locate the module files
set(CMAKE_Fortran_MODULE_DIRECTORY ${PROJECT_SOURCE_DIR}/include)

# Locate header files
include_directories(${PROJECT_SOURCE_DIR}/include)

# Define output directories, if undefined
if (NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
message(STATUS "FPLOT library output directories undefined. Using default directories.")
Expand Down
157 changes: 118 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ program example
type(plot_2d) :: plt
type(plot_data_2d) :: d1, d2
class(plot_axis), pointer :: xAxis, yAxis
class(legend), pointer :: lgnd
! Initialize the plot object
call plt%initialize()
Expand All @@ -38,6 +39,9 @@ program example
yAxis => plt%get_y_axis()
call yAxis%set_title("Y Axis")
lgnd => plt%get_legend()
call lgnd%set_is_visible(.true.)
! Define the data, and then add it to the plot
x(1) = 0.0d0
do i = 2, n
Expand Down Expand Up @@ -104,6 +108,7 @@ program example
! Define the legend location
lgnd => plt%get_legend()
call lgnd%set_is_visible(.true.)
call lgnd%set_draw_inside_axes(.false.)
! Define titles
Expand Down Expand Up @@ -131,12 +136,10 @@ program example
! Define properties for each data set
call d1%set_name("Data Set 1")
call d1%set_use_auto_color(.false.)
call d1%set_line_color(CLR_BLUE)
call d1%set_line_width(1.0)
call d2%set_name("Data Set 2")
call d2%set_use_auto_color(.false.)
call d2%set_line_color(CLR_GREEN)
call d2%set_line_style(LINE_DASHED)
call d2%set_line_width(2.0)
Expand Down Expand Up @@ -219,6 +222,119 @@ end program
This is the plot resulting from the above program.
![](images/example_surf_plot_1.png?raw=true)

## Example 4
The following example illustrates how to create a vector-field plot.
```fortran
program example
use iso_fortran_env
use fplot_core
implicit none
! Local Variables
type(plot_2d) :: plt
type(vector_field_plot_data) :: ds1
class(plot_axis), pointer :: xAxis, yAxis
type(rainbow_colormap) :: cmap
real(real64), allocatable, dimension(:,:,:) :: pts
real(real64), allocatable, dimension(:,:) :: dx, dy
real(real64) :: dxdt(2)
integer(int32) :: i, j
! Create a grid of points defining the vector locations
pts = meshgrid( &
linspace(-2.0d0, 2.0d0, 20), &
linspace(-5.0d0, 5.0d0, 20))
! Compute the values of each derivative
allocate(dx(size(pts, 1), size(pts, 2)))
allocate(dy(size(pts, 1), size(pts, 2)))
do j = 1, size(pts, 2)
do i = 1, size(pts, 1)
call eqn([pts(i,j,1), pts(i,j,2)], dxdt)
dx(i,j) = dxdt(1)
dy(i,j) = dxdt(2)
end do
end do
! Define arrow properties
call ds1%set_arrow_size(0.1d0) ! 1.0 by default
call ds1%set_fill_arrow(.true.) ! .false. by default
! Create the plot
call plt%initialize()
call plt%set_font_size(14)
xAxis => plt%get_x_axis()
yAxis => plt%get_y_axis()
! Define axis labels
call xAxis%set_title("x(t)")
call yAxis%set_title("dx/dt")
! Set plot style information
call xAxis%set_zero_axis(.true.)
call yAxis%set_zero_axis(.true.)
call plt%set_draw_border(.false.)
call plt%set_show_gridlines(.false.)
! Define the colormap
call plt%set_colormap(cmap)
! Add the data to the plot - color by the magnitude of gradient
call ds1%define_data(pts(:,:,1), pts(:,:,2), dx, dy, sqrt(dx**2 + dy**2))
call plt%push(ds1)
call plt%draw()
contains
! Van der Pol Equation
! x" - mu * (1 - x^2) * x' + x = 0
subroutine eqn(x, dxdt)
real(real64), intent(in) :: x(2)
real(real64), intent(out) :: dxdt(2)
real(real64), parameter :: mu = 2.0d0
dxdt(1) = x(2)
dxdt(2) = mu * (1.0d0 - x(1)**2) * x(2) - x(1)
end subroutine
end program
```
This is the plot resulting from the above program.
![](images/vector_plot_2.png?raw=true)

## Example 5
The following example illustrates how to create a polar plot.
```fortran
program example
use iso_fortran_env
use fplot_core
! Local Variables
integer(int32), parameter :: npts = 1000
real(real64), parameter :: pi = 2.0d0 * acos(0.0d0)
real(real64) :: t(npts), x(npts)
type(plot_polar) :: plt
type(plot_data_2d) :: pd
! Create a function to plot
t = linspace(-2.0d0 * pi, 2.0d0 * pi, npts)
x = t * sin(t)
! Plot the function
call plt%initialize()
call plt%set_font_size(14)
call plt%set_title("Polar Plot Example")
call plt%set_autoscale(.false.)
call plt%set_radial_limits([0.0d0, 6.0d0])
call pd%define_data(t, x)
call pd%set_line_width(2.0)
call plt%push(pd)
call plt%draw()
end program
```
This is the plot resulting from the above program.
![](images/polar_example_1.png?raw=true)

## Building FPLOT
This library can be built using CMake. For instructions see [Running CMake](https://cmake.org/runningcmake/).

Expand All @@ -229,40 +345,3 @@ Documentation can be found [here](http://htmlpreview.github.io/?https://github.c
The FPLOT library depends upon the following libraries.
- [FERROR](https://github.com/jchristopherson/ferror)
- [FCORE](https://github.com/jchristopherson/fcore)

## Using FPLOT
Using fplot in an application utilizing CMake is straight forward. The following CMake script illustrates a bare bones implementation that generates and runs an executable by the name of "plot."
```text
# Master CMAKE Build Script
cmake_minimum_required(VERSION 3.7)
project(plot Fortran)
# Get FPLOT
find_package(fplot)
find_package(ferror)
# Build the executable
add_executable(plot plot.f90)
target_link_libraries(plot fplot)
# Copy the necessary DLL's to the application directory - Assuming Windows for an OS
get_target_property(ferror_LibLocation ferror LOCATION)
add_custom_command(TARGET plot POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${ferror_LibLocation} $<TARGET_FILE_DIR:plot>
)
get_target_property(fplot_LibLocation fplot LOCATION)
add_custom_command(TARGET plot POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${fplot_LibLocation} $<TARGET_FILE_DIR:plot>
)
# Run the executable
add_custom_command(
OUTPUT plot_output
COMMAND plot
)
add_custom_target(run_plot ALL DEPENDS plot_output)
```
2 changes: 1 addition & 1 deletion doc/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = fplot
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 1.5.0
PROJECT_NUMBER = 1.6.0

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
Loading

0 comments on commit f1d0a20

Please sign in to comment.