diff --git a/CHANGELOG.md b/CHANGELOG.md index cb4ded9..e0c7228 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ All notable changes to the gtk-fortran project are documented in this file. The * A `colorbar()` type-bound procedure to write a PPM file with the colorbar. ### Changed +* Subroutine `test_colormap()`: the `encoding` argument is now optional (binary by default). * The colormap `inverted_rainbow` was renamed `inv_rainbow`. * `TODO.md` was refactored and renamed `ROADMAP.md`. * Code refactoring. diff --git a/example/demo.f90 b/example/demo.f90 index afc01b0..872fedc 100644 --- a/example/demo.f90 +++ b/example/demo.f90 @@ -1,6 +1,6 @@ ! The MIT License (MIT) ! -! Copyright (c) 2023 Vincent Magnin +! Copyright (c) 2023-2024 Vincent Magnin ! ! Permission is hereby granted, free of charge, to any person obtaining a copy ! of this software and associated documentation files (the "Software"), to deal @@ -21,7 +21,7 @@ ! SOFTWARE. !------------------------------------------------------------------------------- ! Contributed by vmagnin: 2023-09-26 -! Last modification: gha3mi 2024-01-28, vmagnin 2024-02-21 +! Last modification: gha3mi 2024-01-28, vmagnin 2024-02-22 !------------------------------------------------------------------------------- program demo @@ -44,12 +44,12 @@ program demo 255, 255, 255 ], & shape(my_colormap), order = [2, 1] ) - ! Let's create PPM files for each built-in colormap. - ! The built-in z=f(x,y) test function is in the [0, 2] range: + !> 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, size(colormaps_list) call cmap%set(trim(colormaps_list(i)), 0.0_wp, 2.0_wp) call cmap%colorbar(trim(colormaps_list(i))//'_colorbar') - call test_colormap(cmap, trim(colormaps_list(i))//'_test', encoding='binary') + call test_colormap(cmap, trim(colormaps_list(i))//'_test') print '("Colormap ", A30, " has ", I0, " levels")', trim(cmap%get_name()), cmap%get_levels() end do @@ -57,17 +57,17 @@ program demo 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 test_colormap(cmap, 'cubehelix_customized_test', encoding='binary') + call test_colormap(cmap, 'cubehelix_customized_test') ! 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%colorbar('discrete_colorbar') - call test_colormap(custom_cmap, 'discrete_test', encoding='binary') + call test_colormap(custom_cmap, 'discrete_test') ! 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%colorbar('a_loaded_colorbar') - call test_colormap(custom_cmap, 'a_loaded_colormap_test', encoding='binary') + call test_colormap(custom_cmap, 'a_loaded_colormap_test') call custom_cmap%print() end program demo diff --git a/example/demo_reverse.f90 b/example/demo_reverse.f90 index 11e9c8b..d9d61a1 100644 --- a/example/demo_reverse.f90 +++ b/example/demo_reverse.f90 @@ -1,6 +1,6 @@ ! The MIT License (MIT) ! -! Copyright (c) 2023 Vincent Magnin +! Copyright (c) 2023-2024 Vincent Magnin ! ! Permission is hereby granted, free of charge, to any person obtaining a copy ! of this software and associated documentation files (the "Software"), to deal @@ -21,7 +21,7 @@ ! SOFTWARE. !------------------------------------------------------------------------------- ! Contributed by vmagnin: 2023-09-26 -! Last modification: gha3mi 2023-11-01, vmagnin 2024-02-21 +! Last modification: gha3mi 2023-11-01, vmagnin 2024-02-22 !------------------------------------------------------------------------------- program demo_reverse @@ -43,12 +43,12 @@ program demo_reverse 255, 255, 255 ], & shape(my_colormap), order = [2, 1] ) - ! Let's create PPM files for each built-in colormap. - ! The built-in z=f(x,y) test function is in the [0, 2] range: + !> 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, size(colormaps_list) call cmap%set(trim(colormaps_list(i)), 0.0_wp, 2.0_wp, reverse=.true.) call cmap%colorbar(trim(colormaps_list(i))//'_reverse_colorbar') - call test_colormap(cmap, trim(colormaps_list(i))//'_reverse_test', encoding='binary') + call test_colormap(cmap, trim(colormaps_list(i))//'_reverse_test') print '("Colormap ", A30, " has ", I0, " levels")', trim(cmap%get_name()), cmap%get_levels() end do @@ -56,17 +56,17 @@ program demo_reverse 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.) ! We change the name for the output test files: call cmap%colorbar('cubehelix_customized_reverse_colorbar') - call test_colormap(cmap, 'cubehelix_customized_reverse_test', encoding='binary') + call test_colormap(cmap, 'cubehelix_customized_reverse_test') ! You can create your own colormap defined in an array: call custom_cmap%create('discrete', 0.0_wp, 2.0_wp, my_colormap, reverse=.true.) call custom_cmap%colorbar('discrete_reverse_colorbar') - call test_colormap(custom_cmap, 'discrete_reverse_test', encoding='binary') + call test_colormap(custom_cmap, 'discrete_reverse_test') ! Or you can download it from a .txt file: call custom_cmap%load("test_map_to_load.txt", 0.0_wp, 2.0_wp, reverse=.true.) call custom_cmap%colorbar('a_loaded_reverse_colorbar') - call test_colormap(custom_cmap, 'a_loaded_reverse_colormap_test', encoding='binary') + call test_colormap(custom_cmap, 'a_loaded_reverse_colormap_test') call custom_cmap%print() end program demo_reverse diff --git a/src/forcolormap_utils.f90 b/src/forcolormap_utils.f90 index 045110b..18c7fa1 100644 --- a/src/forcolormap_utils.f90 +++ b/src/forcolormap_utils.f90 @@ -21,7 +21,7 @@ ! SOFTWARE. !------------------------------------------------------------------------------- ! Contributed by vmagnin & gha3mi: 2024-02-21 -! Last modification: vmagnin 2024-02-21 +! Last modification: vmagnin 2024-02-22 !------------------------------------------------------------------------------- !> This module contains miscellaneous procedures and functions. @@ -37,7 +37,8 @@ module forcolormap_utils contains !> This procedure computes a default z=f(x,y) function and plot it - !> in a .ppm file using the specified colormap. + !> in a .ppm file using the specified colormap. That function is defined + !> in the [0, 2] range. subroutine test_colormap(self, filename, encoding) use forimage, only: format_pnm type(Colormap), intent(inout) :: self @@ -49,7 +50,7 @@ subroutine test_colormap(self, filename, encoding) integer :: red, green, blue real(wp) :: z type(format_pnm) :: ppm - character(*), intent(in) :: encoding + character(*), intent(in), optional :: encoding !> Default is binary allocate(rgb_image(pixheight,pixwidth*3)) @@ -65,12 +66,18 @@ subroutine test_colormap(self, filename, encoding) end do end do - call ppm%set_pnm(encoding = encoding,& + if (present(encoding)) then + call ppm%set_format(encoding) + else + call ppm%set_format('binary') + end if + + call ppm%set_pnm(encoding = ppm%get_format(),& file_format = 'ppm',& width = pixwidth,& height = pixheight,& max_color = 255,& - comment = 'comment',& + comment = 'Test generated by ForColormap',& pixels = rgb_image) call ppm%export_pnm(filename)