fortplot_figure_management Module

Figure lifecycle management module for fortplot_figure_core

This module handles figure lifecycle, initialization, I/O operations, animation support, and cleanup. Extracted from fortplot_figure_core.f90 for better organization following Single Responsibility Principle.

Responsibilities: - Figure initialization and destruction - File I/O operations (savefig, show) - Animation support (PNG backend setup, data extraction) - Streamline data management - Subplot management

============================================================================= CORE MODULE DELEGATION WRAPPERS Simple wrapper procedures for core module delegation pattern =============================================================================



Functions

public function figure_subplot_plot_count(subplots_array, subplot_rows, subplot_cols, row, col) result(count)

Get the number of plots in a specific subplot

Arguments

Type IntentOptional Attributes Name
type(subplot_data_t), intent(in) :: subplots_array(:,:)
integer, intent(in) :: subplot_rows
integer, intent(in) :: subplot_cols
integer, intent(in) :: row
integer, intent(in) :: col

Return Value integer

public function figure_subplot_title(subplots_array, subplot_rows, subplot_cols, row, col) result(title)

Get the title for a specific subplot

Arguments

Type IntentOptional Attributes Name
type(subplot_data_t), intent(in) :: subplots_array(:,:)
integer, intent(in) :: subplot_rows
integer, intent(in) :: subplot_cols
integer, intent(in) :: row
integer, intent(in) :: col

Return Value character(len=:), allocatable


Subroutines

public subroutine figure_initialize(state, plots, streamlines, subplots_array, subplot_rows, subplot_cols, current_subplot, title_target, xlabel_target, ylabel_target, plot_count, width, height, backend)

Initialize the figure with specified dimensions and backend

Arguments

Type IntentOptional Attributes Name
type(figure_state_t), intent(inout) :: state
type(plot_data_t), intent(inout), allocatable :: plots(:)
type(plot_data_t), intent(inout), allocatable :: streamlines(:)
type(subplot_data_t), intent(inout), allocatable :: subplots_array(:,:)
integer, intent(inout) :: subplot_rows
integer, intent(inout) :: subplot_cols
integer, intent(inout) :: current_subplot
character(len=:), intent(inout), allocatable :: title_target
character(len=:), intent(inout), allocatable :: xlabel_target
character(len=:), intent(inout), allocatable :: ylabel_target
integer, intent(inout) :: plot_count
integer, intent(in), optional :: width
integer, intent(in), optional :: height
character(len=*), intent(in), optional :: backend

public subroutine figure_destroy(state, plots, streamlines, title_target, xlabel_target, ylabel_target)

Finalize and clean up figure

Arguments

Type IntentOptional Attributes Name
type(figure_state_t), intent(inout) :: state
type(plot_data_t), intent(inout), allocatable :: plots(:)
type(plot_data_t), intent(inout), allocatable :: streamlines(:)
character(len=:), intent(inout), allocatable :: title_target
character(len=:), intent(inout), allocatable :: xlabel_target
character(len=:), intent(inout), allocatable :: ylabel_target

public subroutine figure_savefig(state, plots, plot_count, filename, blocking, annotations, annotation_count, subplots_array, subplot_rows, subplot_cols)

Save figure to file (backward compatibility version)

Arguments

Type IntentOptional Attributes Name
type(figure_state_t), intent(inout) :: state
type(plot_data_t), intent(inout) :: plots(:)
integer, intent(in) :: plot_count
character(len=*), intent(in) :: filename
logical, intent(in), optional :: blocking
type(text_annotation_t), intent(in), optional :: annotations(:)
integer, intent(in), optional :: annotation_count
type(subplot_data_t), intent(in), optional :: subplots_array(:,:)
integer, intent(in), optional :: subplot_rows
integer, intent(in), optional :: subplot_cols

public subroutine figure_savefig_with_status(state, plots, plot_count, filename, status, blocking, annotations, annotation_count, subplots_array, subplot_rows, subplot_cols)

Save figure to file with error status reporting

Arguments

Type IntentOptional Attributes Name
type(figure_state_t), intent(inout) :: state
type(plot_data_t), intent(inout) :: plots(:)
integer, intent(in) :: plot_count
character(len=*), intent(in) :: filename
integer, intent(out) :: status
logical, intent(in), optional :: blocking
type(text_annotation_t), intent(in), optional :: annotations(:)
integer, intent(in), optional :: annotation_count
type(subplot_data_t), intent(in), optional :: subplots_array(:,:)
integer, intent(in), optional :: subplot_rows
integer, intent(in), optional :: subplot_cols

public subroutine figure_show(state, plots, plot_count, blocking, annotations, annotation_count, subplots_array, subplot_rows, subplot_cols)

Display the figure

Arguments

Type IntentOptional Attributes Name
type(figure_state_t), intent(inout) :: state
type(plot_data_t), intent(inout) :: plots(:)
integer, intent(in) :: plot_count
logical, intent(in), optional :: blocking
type(text_annotation_t), intent(in), optional :: annotations(:)
integer, intent(in), optional :: annotation_count
type(subplot_data_t), intent(in), optional :: subplots_array(:,:)
integer, intent(in), optional :: subplot_rows
integer, intent(in), optional :: subplot_cols

public subroutine figure_clear(state, streamlines, subplots_array, subplot_rows, subplot_cols, current_subplot, title_target, xlabel_target, ylabel_target, plot_count, annotation_count)

Clear the figure to prepare for reuse (preserving backend settings)

Arguments

Type IntentOptional Attributes Name
type(figure_state_t), intent(inout) :: state
type(plot_data_t), intent(inout), allocatable :: streamlines(:)
type(subplot_data_t), intent(inout), allocatable :: subplots_array(:,:)
integer, intent(inout) :: subplot_rows
integer, intent(inout) :: subplot_cols
integer, intent(inout) :: current_subplot
character(len=:), intent(inout), allocatable :: title_target
character(len=:), intent(inout), allocatable :: xlabel_target
character(len=:), intent(inout), allocatable :: ylabel_target
integer, intent(inout) :: plot_count
integer, intent(inout) :: annotation_count

public subroutine figure_clear_streamlines(streamlines)

Clear streamline data

Arguments

Type IntentOptional Attributes Name
type(plot_data_t), intent(inout), allocatable :: streamlines(:)

public subroutine figure_setup_png_backend_for_animation(state)

Setup PNG backend for animation

Arguments

Type IntentOptional Attributes Name
type(figure_state_t), intent(inout) :: state

public subroutine figure_extract_rgb_data_for_animation(state, rgb_data, rendered)

Extract RGB data for animation

Arguments

Type IntentOptional Attributes Name
type(figure_state_t), intent(inout) :: state
real(kind=wp), intent(out) :: rgb_data(:,:,:)
logical, intent(in) :: rendered

public subroutine figure_extract_png_data_for_animation(state, png_data, status, rendered)

Extract PNG data for animation

Arguments

Type IntentOptional Attributes Name
type(figure_state_t), intent(inout) :: state
integer(kind=1), intent(out), allocatable :: png_data(:)
integer, intent(out) :: status
logical, intent(in) :: rendered

public subroutine figure_subplots(subplots_array, subplot_rows, subplot_cols, current_subplot, nrows, ncols)

Create a grid of subplots

Arguments

Type IntentOptional Attributes Name
type(subplot_data_t), intent(inout), allocatable :: subplots_array(:,:)
integer, intent(inout) :: subplot_rows
integer, intent(inout) :: subplot_cols
integer, intent(inout) :: current_subplot
integer, intent(in) :: nrows
integer, intent(in) :: ncols

public subroutine figure_subplot_plot(subplots_array, subplot_rows, subplot_cols, row, col, x, y, label, linestyle, color, colors, num_colors)

Add a plot to a specific subplot

Arguments

Type IntentOptional Attributes Name
type(subplot_data_t), intent(inout) :: subplots_array(:,:)
integer, intent(in) :: subplot_rows
integer, intent(in) :: subplot_cols
integer, intent(in) :: row
integer, intent(in) :: col
real(kind=wp), intent(in) :: x(:)
real(kind=wp), intent(in) :: y(:)
character(len=*), intent(in), optional :: label
character(len=*), intent(in), optional :: linestyle
real(kind=wp), intent(in), optional :: color(3)
real(kind=wp), intent(in) :: colors(:,:)
integer, intent(in) :: num_colors

public subroutine figure_subplot_set_title(subplots_array, subplot_rows, subplot_cols, row, col, title)

Set the title for a specific subplot

Arguments

Type IntentOptional Attributes Name
type(subplot_data_t), intent(inout) :: subplots_array(:,:)
integer, intent(in) :: subplot_rows
integer, intent(in) :: subplot_cols
integer, intent(in) :: row
integer, intent(in) :: col
character(len=*), intent(in) :: title

public subroutine figure_subplot_set_xlabel(subplots_array, subplot_rows, subplot_cols, row, col, xlabel)

Set the x-axis label for a specific subplot

Arguments

Type IntentOptional Attributes Name
type(subplot_data_t), intent(inout) :: subplots_array(:,:)
integer, intent(in) :: subplot_rows
integer, intent(in) :: subplot_cols
integer, intent(in) :: row
integer, intent(in) :: col
character(len=*), intent(in) :: xlabel

public subroutine figure_subplot_set_ylabel(subplots_array, subplot_rows, subplot_cols, row, col, ylabel)

Set the y-axis label for a specific subplot

Arguments

Type IntentOptional Attributes Name
type(subplot_data_t), intent(inout) :: subplots_array(:,:)
integer, intent(in) :: subplot_rows
integer, intent(in) :: subplot_cols
integer, intent(in) :: row
integer, intent(in) :: col
character(len=*), intent(in) :: ylabel

public subroutine core_clear(state, streamlines, subplots_array, subplot_rows, subplot_cols, current_subplot, title_target, xlabel_target, ylabel_target, plot_count, annotation_count)

Clear the figure for reuse, preserving backend settings

Arguments

Type IntentOptional Attributes Name
type(figure_state_t), intent(inout) :: state
type(plot_data_t), intent(inout), allocatable :: streamlines(:)
type(subplot_data_t), intent(inout), allocatable :: subplots_array(:,:)
integer, intent(inout) :: subplot_rows
integer, intent(inout) :: subplot_cols
integer, intent(inout) :: current_subplot
character(len=:), intent(inout), allocatable :: title_target
character(len=:), intent(inout), allocatable :: xlabel_target
character(len=:), intent(inout), allocatable :: ylabel_target
integer, intent(inout) :: plot_count
integer, intent(inout) :: annotation_count

public subroutine core_clear_streamlines(streamlines)

Arguments

Type IntentOptional Attributes Name
type(plot_data_t), intent(inout), allocatable :: streamlines(:)

public subroutine core_destroy(state, plots, streamlines, title_target, xlabel_target, ylabel_target)

Arguments

Type IntentOptional Attributes Name
type(figure_state_t), intent(inout) :: state
type(plot_data_t), intent(inout), allocatable :: plots(:)
type(plot_data_t), intent(inout), allocatable :: streamlines(:)
character(len=:), intent(inout), allocatable :: title_target
character(len=:), intent(inout), allocatable :: xlabel_target
character(len=:), intent(inout), allocatable :: ylabel_target