|
28 | 28 | !> the corresponding test images. It also demonstrates how you can create your |
29 | 29 | !> own colormap defined in an array, or import it from a text file. |
30 | 30 | 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 |
35 | 33 |
|
36 | | - integer :: i |
37 | | - type(Colormap) :: cmap, custom_cmap |
| 34 | + integer :: i |
| 35 | + type(Colormap) :: cmap, custom_cmap |
38 | 36 |
|
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] ) |
57 | 55 |
|
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 |
66 | 64 |
|
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]) |
72 | 70 |
|
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 |
79 | 86 |
|
80 | 87 | end program demo |
0 commit comments