demo Program

Uses

  • program~~demo~~UsesGraph program~demo demo module~forcolormap forcolormap program~demo->module~forcolormap module~forcolormap_cm_matplotlib forcolormap_cm_matplotlib module~forcolormap->module~forcolormap_cm_matplotlib module~forcolormap_cm_miscellaneous forcolormap_cm_miscellaneous module~forcolormap->module~forcolormap_cm_miscellaneous module~forcolormap_cm_scientific forcolormap_cm_scientific module~forcolormap->module~forcolormap_cm_scientific module~forcolormap_info forcolormap_info module~forcolormap->module~forcolormap_info module~forcolormap_parameters forcolormap_parameters module~forcolormap->module~forcolormap_parameters module~forcolormap_utils forcolormap_utils module~forcolormap->module~forcolormap_utils module~forcolormap_cm_matplotlib->module~forcolormap_parameters module~forcolormap_cm_miscellaneous->module~forcolormap_parameters module~forcolormap_cm_scientific->module~forcolormap_parameters module~forcolormap_info->module~forcolormap_cm_matplotlib module~forcolormap_info->module~forcolormap_cm_miscellaneous module~forcolormap_info->module~forcolormap_cm_scientific module~forcolormap_info->module~forcolormap_parameters iso_fortran_env iso_fortran_env module~forcolormap_parameters->iso_fortran_env module~forcolormap_utils->module~forcolormap_parameters

This example will create colorbar files for each available colormap and the corresponding test images. It also demonstrates how you can create your own colormap defined in an array, or import it from a text file. The name of your colormap must conform to the max length defined in forcolormap_parameters.f90 You can also download your colormap from a .txt file by using the load() method instead of the set() method.


Calls

program~~demo~~CallsGraph program~demo demo proc~create Colormap%create program~demo->proc~create proc~get_levels Colormap%get_levels program~demo->proc~get_levels proc~get_name~2 Colormaps_info%get_name program~demo->proc~get_name~2 proc~get_ncolormaps Colormaps_info%get_ncolormaps program~demo->proc~get_ncolormaps proc~load Colormap%load program~demo->proc~load proc~set Colormap%set program~demo->proc~set proc~write_ppm_colorbar Colormap%write_ppm_colorbar program~demo->proc~write_ppm_colorbar proc~assign_map Colormap%assign_map proc~create->proc~assign_map proc~check Colormap%check proc~create->proc~check proc~reverse Colormap%reverse proc~create->proc~reverse proc~load->proc~check proc~load->proc~reverse proc~set->proc~assign_map proc~set->proc~check proc~cubehelix_colormap cubehelix_colormap proc~set->proc~cubehelix_colormap proc~fire_colormap fire_colormap proc~set->proc~fire_colormap proc~inv_rainbow_colormap inv_rainbow_colormap proc~set->proc~inv_rainbow_colormap proc~rainbow_colormap rainbow_colormap proc~set->proc~rainbow_colormap proc~set->proc~reverse proc~zebra_colormap zebra_colormap proc~set->proc~zebra_colormap export_pnm export_pnm proc~write_ppm_colorbar->export_pnm get_format get_format proc~write_ppm_colorbar->get_format local local proc~write_ppm_colorbar->local proc~compute_rgb Colormap%compute_RGB proc~write_ppm_colorbar->proc~compute_rgb set_format set_format proc~write_ppm_colorbar->set_format set_pnm set_pnm proc~write_ppm_colorbar->set_pnm proc~find_index Colormaps_info%find_index proc~check->proc~find_index proc~get_levels~2 Colormaps_info%get_levels proc~check->proc~get_levels~2 proc~get_rgb Colormap%get_RGB proc~compute_rgb->proc~get_rgb proc~cubehelix_colormap->local

Variables

Type Attributes Name Initial
type(Colormap) :: cmap
type(Colormap) :: custom_cmap
integer :: i
integer, dimension(0:7, 3) :: my_colormap = reshape([198, 29, 32, 189, 21, 56, 171, 82, 150, 102, 81, 156, 38, 53, 108, 5, 65, 40, 221, 199, 44, 237, 191, 44], shape(my_colormap), order=[2, 1])

A discrete colormap with 8 levels, by @alozada, resembling the color changes in red cabbage (containing Anthocyanins) with pH:

real(kind=wp), parameter, dimension(2) :: xmax = [599.0_wp, 599.0_wp]
real(kind=wp), parameter, dimension(2) :: xmin = [0.0_wp, 0.0_wp]

Functions

pure function zfun(x, y) result(z)

A sample test function to generate colormap images.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: x
real(kind=wp), intent(in) :: y

Return Value real(kind=wp)


Source Code

program demo
   use forcolormap, only: Colormap, wp, cmap_info
   implicit none

   integer :: i
   type(Colormap) :: cmap, custom_cmap
   real(wp), dimension(2), parameter :: xmin = [0.0_wp, 0.0_wp]
   real(wp), dimension(2), parameter :: xmax = [599.0_wp, 599.0_wp]

   !> A discrete colormap with 8 levels, by @alozada, resembling the color
   !> changes in red cabbage (containing Anthocyanins) with pH:
   integer, dimension(0:7, 3) :: my_colormap = reshape( [ &
      198,    29,    32,   &
      189,    21,    56,   &
      171,    82,   150,   &
      102,    81,   156,   &
      38,    53,   108,   &
      5,    65,    40,   &
      221,   199,    44,   &
      237,   191,    44 ], &
      shape(my_colormap), order = [2, 1] )
   !> The name of your colormap must conform to the max length
   !> defined in forcolormap_parameters.f90
   ! Use the create() method instead of the set() method.
   call custom_cmap%create('red_cabbage', 0.0_wp, 2.0_wp, my_colormap)
   call custom_cmap%colorbar('red_cabbage_colorbar')
   call custom_cmap%colormap('red_cabbage_test', zfun, xmin, xmax)

   ! We create PPM files (binary encoded by default) for each built-in colormap.
   ! The built-in z=f(x,y) test function is in the [0, 2] range:
   do i = 1, cmap_info%get_ncolormaps()
      call cmap%set(trim(cmap_info%get_name(i)), 0.0_wp, 2.0_wp)
      call cmap%colorbar(trim(cmap_info%get_name(i))//'_colorbar')
      call cmap%colormap(trim(cmap_info%get_name(i))//'_test', zfun, xmin, xmax)
      print '("Colormap ", A30, " has ", I0, " levels")', trim(cmap%get_name()), cmap%get_levels()
   end do

   ! Cubehelix can also accept other parameters (varargs array):
   call cmap%set("cubehelix", 0.0_wp, 2.0_wp, 1024, [0.5_wp, -1.0_wp, 1.0_wp, 1.0_wp])
   ! We change the name for the output test files:
   call cmap%colorbar('cubehelix_customized_colorbar')
   call cmap%colormap('cubehelix_customized_test', zfun, xmin, xmax)

   !> You can also download your colormap from a .txt file by
   !> using the load() method instead of the set() method.
   call custom_cmap%load("test_map_to_load.txt", 0.0_wp, 2.0_wp)
   call custom_cmap%colorbar('a_loaded_colorbar')
   call custom_cmap%colormap('a_loaded_colormap_test', zfun, xmin, xmax)
   call custom_cmap%print()

contains

   !> A sample test function to generate colormap images.
   pure function zfun(x,y) result(z)
      real(wp), intent(in) :: x, y
      real(wp) :: z
      z = 1.0_wp + sin(x*y/10000.0_wp) * cos(y/100.0_wp)
   end function

end program demo