Skip to content

Commit 52811d8

Browse files
committed
add colormap method with a function argument
1 parent bd810ba commit 52811d8

File tree

7 files changed

+210
-153
lines changed

7 files changed

+210
-153
lines changed

example/CMakeLists.txt

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,34 @@
1-
# Build example_utils as a library
2-
add_library(example_utils example_utils.f90)
3-
target_link_libraries(example_utils ${PROJECT_NAME})
4-
51
# DEMO_REVERSE
62
add_executable(demo_reverse
73
demo_reverse.f90)
8-
target_link_libraries(demo_reverse example_utils ${PROJECT_NAME})
4+
target_link_libraries(demo_reverse PRIVATE forcolormap)
95

106
# DEMO
117
add_executable(demo
128
demo.f90)
13-
target_link_libraries(demo example_utils ${PROJECT_NAME})
9+
target_link_libraries(demo PRIVATE forcolormap)
1410

1511
# EXAMPLE1
1612
add_executable(example1
1713
example1.f90)
18-
target_link_libraries(example1 example_utils ${PROJECT_NAME})
14+
target_link_libraries(example1 PRIVATE forcolormap)
1915

2016
# EXTRACT
2117
add_executable(extract
2218
extract.f90)
23-
target_link_libraries(extract ${PROJECT_NAME})
19+
target_link_libraries(extract PRIVATE forcolormap)
2420

2521
# INFO
2622
add_executable(info
2723
info.f90)
28-
target_link_libraries(info ${PROJECT_NAME})
24+
target_link_libraries(info PRIVATE forcolormap)
2925

3026
# MODIFY
3127
add_executable(modify
3228
modify.f90)
33-
target_link_libraries(modify ${PROJECT_NAME})
29+
target_link_libraries(modify PRIVATE forcolormap)
3430

3531
# CREATE
3632
add_executable(create
3733
create.f90)
38-
target_link_libraries(create ${PROJECT_NAME})
34+
target_link_libraries(create PRIVATE forcolormap)

example/demo.f90

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -28,53 +28,60 @@
2828
!> the corresponding test images. It also demonstrates how you can create your
2929
!> own colormap defined in an array, or import it from a text file.
3030
program demo
31-
use forcolormap, only: Colormap, wp
32-
use forcolormap_info, only: cmap_info
33-
use example_utils, only: test_colormap
34-
implicit none
31+
use forcolormap, only: Colormap, wp, cmap_info
32+
implicit none
3533

36-
integer :: i
37-
type(Colormap) :: cmap, custom_cmap
34+
integer :: i
35+
type(Colormap) :: cmap, custom_cmap
3836

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

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

67-
! Cubehelix can also accept other parameters (varargs array):
68-
call cmap%set("cubehelix", 0.0_wp, 2.0_wp, 1024, [0.5_wp, -1.0_wp, 1.0_wp, 1.0_wp])
69-
! We change the name for the output test files:
70-
call cmap%colorbar('cubehelix_customized_colorbar')
71-
call test_colormap(cmap, 'cubehelix_customized_test')
65+
! Cubehelix can also accept other parameters (varargs array):
66+
call cmap%set("cubehelix", 0.0_wp, 2.0_wp, 1024, [0.5_wp, -1.0_wp, 1.0_wp, 1.0_wp])
67+
! We change the name for the output test files:
68+
call cmap%colorbar('cubehelix_customized_colorbar')
69+
call cmap%colormap('cubehelix_customized_test', zfun, [0.0_wp, 0.0_wp], [599.0_wp, 599.0_wp])
7270

73-
!> You can also download your colormap from a .txt file by
74-
!> using the load() method instead of the set() method.
75-
call custom_cmap%load("test_map_to_load.txt", 0.0_wp, 2.0_wp)
76-
call custom_cmap%colorbar('a_loaded_colorbar')
77-
call test_colormap(custom_cmap, 'a_loaded_colormap_test')
78-
call custom_cmap%print()
71+
!> You can also download your colormap from a .txt file by
72+
!> using the load() method instead of the set() method.
73+
call custom_cmap%load("test_map_to_load.txt", 0.0_wp, 2.0_wp)
74+
call custom_cmap%colorbar('a_loaded_colorbar')
75+
call custom_cmap%colormap('a_loaded_colormap_test', zfun, [0.0_wp, 0.0_wp], [599.0_wp, 599.0_wp])
76+
call custom_cmap%print()
77+
78+
contains
79+
80+
!> A sample test function to generate colormap images.
81+
pure function zfun(x,y) result(z)
82+
real(wp), intent(in) :: x, y
83+
real(wp) :: z
84+
z = 1.0_wp + sin(x*y/10000.0_wp) * cos(y/100.0_wp)
85+
end function
7986

8087
end program demo

example/demo_reverse.f90

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@
2727
!> This example demonstrates the use of the 'reverse' optional argument to
2828
!> reverse the order of a colormap.
2929
program demo_reverse
30-
use forcolormap, only: Colormap, wp
31-
use forcolormap_info, only: cmap_info
32-
use example_utils, only: test_colormap
30+
use forcolormap, only: Colormap, wp, cmap_info
3331
implicit none
3432

3533
integer :: i
@@ -52,28 +50,36 @@ program demo_reverse
5250
! Use the create() method instead of the set() method.
5351
call custom_cmap%create('red_cabbage_reverse', 0.0_wp, 2.0_wp, my_colormap, reverse=.true.)
5452
call custom_cmap%colorbar('red_cabbage_reverse_colorbar')
55-
call test_colormap(custom_cmap, 'red_cabbage_reverse_test')
53+
call custom_cmap%colormap('red_cabbage_reverse_test', zfun, [0.0_wp, 0.0_wp], [599.0_wp, 599.0_wp] )
5654

5755
! We create PPM files (binary encoded by default) for each built-in colormap.
5856
! The built-in z=f(x,y) test function is in the [0, 2] range:
5957
do i = 1, cmap_info%get_ncolormaps()
6058
call cmap%set(trim(cmap_info%get_name(i)), 0.0_wp, 2.0_wp, reverse=.true.)
6159
call cmap%colorbar(trim(cmap_info%get_name(i))//'_reverse_colorbar')
62-
call test_colormap(cmap, trim(cmap_info%get_name(i))//'_reverse_test')
60+
call cmap%colormap(trim(cmap_info%get_name(i))//'_reverse_test', zfun, [0.0_wp, 0.0_wp], [599.0_wp, 599.0_wp])
6361
print '("Colormap ", A30, " has ", I0, " levels")', trim(cmap%get_name()), cmap%get_levels()
6462
end do
6563

6664
! Cubehelix can also accept other parameters (varargs array):
6765
call cmap%set("cubehelix", 0.0_wp, 2.0_wp, 1024, [0.5_wp, -1.0_wp, 1.0_wp, 1.0_wp], reverse=.true.)
6866
! We change the name for the output test files:
6967
call cmap%colorbar('cubehelix_customized_reverse_colorbar')
70-
call test_colormap(cmap, 'cubehelix_customized_reverse_test')
68+
call cmap%colormap('cubehelix_customized_reverse_test', zfun, [0.0_wp, 0.0_wp], [599.0_wp, 599.0_wp])
7169

7270
!> You can also download your colormap from a .txt file by
7371
!> using the load() method instead of the set() method.
7472
call custom_cmap%load("test_map_to_load.txt", 0.0_wp, 2.0_wp, reverse=.true.)
7573
call custom_cmap%colorbar('a_loaded_reverse_colorbar')
76-
call test_colormap(custom_cmap, 'a_loaded_reverse_colormap_test')
74+
call custom_cmap%colormap('a_loaded_reverse_colormap_test', zfun, [0.0_wp, 0.0_wp], [599.0_wp, 599.0_wp])
7775
call custom_cmap%print()
7876

77+
contains
78+
79+
pure function zfun(x,y) result(z)
80+
real(wp), intent(in) :: x, y
81+
real(wp) :: z
82+
z = 1.0_wp + sin(x*y/10000.0_wp) * cos(y/100.0_wp)
83+
end function
84+
7985
end program demo_reverse

example/example1.f90

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
!> This example demonstrates how ForImage can be used to import/export PPM files.
2828
program example1
2929
use forcolormap, only: Colormap, wp
30-
use example_utils, only: test_colormap
3130
use forimage, only: format_pnm
3231
implicit none
3332

@@ -37,7 +36,7 @@ program example1
3736
! Create ppm files
3837
call custom_cmap%load('test_map_to_load.txt', 0.0_wp, 2.0_wp)
3938
call custom_cmap%colorbar('a_loaded_colormap_ascii_test', encoding='ascii')
40-
call test_colormap(custom_cmap, 'a_loaded_colormap_ascii_colorbar', encoding='ascii')
39+
call custom_cmap%colormap('a_loaded_colormap_ascii_colorbar', zfun, [0.0_wp, 0.0_wp], [599.0_wp, 599.0_wp], encoding='ascii')
4140
call custom_cmap%print()
4241

4342
! Import ascii ppm files
@@ -56,4 +55,12 @@ program example1
5655
call ex1_colormap%finalize()
5756
call ex1_colorbar%finalize()
5857

58+
contains
59+
60+
pure function zfun(x,y) result(z)
61+
real(wp), intent(in) :: x, y
62+
real(wp) :: z
63+
z = 1.0_wp + sin(x*y/10000.0_wp) * cos(y/100.0_wp)
64+
end function
65+
5966
end program example1

example/example_utils.f90

Lines changed: 0 additions & 86 deletions
This file was deleted.

example/info.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
!> Demonstrates how to obtain information about a colormap using
2828
!> the `Colormaps_info` class.
2929
program write_info
30-
use forcolormap_info, only: cmap_info
30+
use forcolormap, only: cmap_info
3131
implicit none
3232

3333
! type(Colormaps_info) :: info

0 commit comments

Comments
 (0)