Skip to content

Commit

Permalink
This commit references issues #3, #4, and #5.
Browse files Browse the repository at this point in the history
Added 'colormap_parameters' module.
Added 'miscellaneous_colormaps' module.
Removed 'test' type-bound procedure.
Moved 'test' subroutine to demo and example1.
Added 'colorbar' type-bound procedure.
Renamed 'get_current' to 'get_name'.
Updated write_ppm_colorbar, set, and print subroutines.
Added pure/impure statements.
Bug fixes: changed 'intent(inout)' to 'intent(in)' in relevant functions.
Updated demo and example1.
  • Loading branch information
gha3mi committed Oct 31, 2023
1 parent bee4729 commit 5e5c1dc
Show file tree
Hide file tree
Showing 7 changed files with 371 additions and 239 deletions.
55 changes: 48 additions & 7 deletions example/demo.f90
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
!-------------------------------------------------------------------------------

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

integer :: i
Expand All @@ -46,21 +46,62 @@ program demo
! The built-in z=f(x,y) test function is in the [0, 2] range:
do i = 1, size(colormaps_list)
call cmap%set(trim(colormaps_list(i)), 0.0_wp, 2.0_wp)
call cmap%test(encoding='binary')
print '("Colormap ", A30, " has ", I0, " levels")', trim(cmap%get_current()), cmap%get_levels()
call cmap%colorbar(trim(colormaps_list(i))//'_colorbar', encoding='binary')
call test_colormap(cmap, trim(colormaps_list(i))//'_test', encoding='binary')
print '("Colormap ", A30, " has ", I0, " levels")', trim(cmap%get_name()), cmap%get_levels()
end do

! Cubehelix can also accept other paramaters (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%test("cubehelix_customized", encoding='binary')
call cmap%colorbar('cubehelix_customized_colorbar', encoding='binary')
call test_colormap(cmap, 'cubehelix_customized_test', encoding='binary')

! You can create your own colormap defined in an array:
call custom_cmap%create("discrete", 0.0_wp, 2.0_wp, my_colormap)
call custom_cmap%test(encoding='binary')
call custom_cmap%create('discrete', 0.0_wp, 2.0_wp, my_colormap)
call custom_cmap%colorbar('discrete_colorbar', encoding='binary')
call test_colormap(custom_cmap, 'discrete_test', encoding='binary')

! Or you can download it from a .txt file:
call custom_cmap%load("test_map_to_load.txt", 0.0_wp, 2.0_wp)
call custom_cmap%test("a_loaded_colormap", encoding='binary')
call custom_cmap%colorbar('a_loaded_colorbar', encoding='binary')
call test_colormap(custom_cmap, 'a_loaded_colormap_test', encoding='binary')
call custom_cmap%print()

contains

subroutine test_colormap(self, filename, encoding)
use forimage, only: format_pnm
type(Colormap), intent(inout) :: self
character(*), intent(in) :: filename
integer :: k, j ! Pixbuffer coordinates
integer, parameter :: pixwidth = 600
integer, parameter :: pixheight = 600
integer, dimension(pixheight,pixwidth*3) :: rgb_image
integer :: red, green, blue
real(wp) :: z
type(format_pnm) :: ppm
character(*), intent(in) :: encoding

do k = 0, pixwidth-1
do j = 0, pixheight-1
! Computing a z=f(x,y) function:
z = 1.0_wp + sin(k*j/10000.0_wp) * cos(j/100.0_wp)
! The corresponding RGB values in our colormap:
call self%compute_RGB(z, red, green, blue)
rgb_image(pixheight-j, 3*(k+1)-2) = red
rgb_image(pixheight-j, 3*(k+1)-1) = green
rgb_image(pixheight-j, 3*(k+1)) = blue
end do
end do

call ppm%set_pnm(encoding = encoding,&
file_format = 'ppm',&
width = pixwidth,&
height = pixheight,&
max_color = 255,&
comment = 'comment',&
pixels = rgb_image)
call ppm%export_pnm(filename)
end subroutine test_colormap
end program demo
42 changes: 40 additions & 2 deletions example/example1.f90
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ program example1
type(format_pnm) :: ex1_colormap, ex1_colorbar

! Create ppm files
call custom_cmap%load("test_map_to_load.txt", 0.0_wp, 2.0_wp)
call custom_cmap%test("a_loaded_colormap_ascii", 'ascii')
call custom_cmap%load('test_map_to_load.txt', 0.0_wp, 2.0_wp)
call custom_cmap%colorbar('a_loaded_colormap_ascii_test', encoding='ascii')
call test_colormap(custom_cmap, 'a_loaded_colormap_ascii_colorbar', encoding='ascii')
call custom_cmap%print()

! Import ascii ppm files
Expand All @@ -54,4 +55,41 @@ program example1
! Deallocate
call ex1_colormap%finalize()
call ex1_colorbar%finalize()

contains

subroutine test_colormap(self, filename, encoding)
use forimage, only: format_pnm
type(Colormap), intent(inout) :: self
character(*), intent(in) :: filename
integer :: k, j ! Pixbuffer coordinates
integer, parameter :: pixwidth = 600
integer, parameter :: pixheight = 600
integer, dimension(pixheight,pixwidth*3) :: rgb_image
integer :: red, green, blue
real(wp) :: z
type(format_pnm) :: ppm
character(*), intent(in) :: encoding

do k = 0, pixwidth-1
do j = 0, pixheight-1
! Computing a z=f(x,y) function:
z = 1.0_wp + sin(k*j/10000.0_wp) * cos(j/100.0_wp)
! The corresponding RGB values in our colormap:
call self%compute_RGB(z, red, green, blue)
rgb_image(pixheight-j, 3*(k+1)-2) = red
rgb_image(pixheight-j, 3*(k+1)-1) = green
rgb_image(pixheight-j, 3*(k+1)) = blue
end do
end do

call ppm%set_pnm(encoding = encoding,&
file_format = 'ppm',&
width = pixwidth,&
height = pixheight,&
max_color = 255,&
comment = 'comment',&
pixels = rgb_image)
call ppm%export_pnm(filename)
end subroutine test_colormap
end program example1
Loading

0 comments on commit 5e5c1dc

Please sign in to comment.