impure subroutine write_ppm_colorbar(self, filename, width, height, encoding)
use forimage, only: format_pnm
class(Colormap), intent(inout) :: self
character(*), intent(in) :: filename
integer :: i, j ! Pixbuffer coordinates
integer, intent(in), optional :: width, height
integer :: pixwidth, pixheight
integer, dimension(:,:), allocatable :: rgb_image
integer :: red, green, blue
real(wp) :: z
type(format_pnm) :: ppm
character(*), intent(in), optional :: encoding
if (present(width)) then
pixwidth = width
else
pixwidth = 600
end if
if (present(height)) then
pixheight = height
else
pixheight = 50
end if
allocate(rgb_image(pixheight,pixwidth*3))
do i = 0, pixwidth-1
do j = 0, pixheight-1
z = self%get_zmin() + i / real(pixwidth-1, kind=wp) * (self%get_zmax() - self%get_zmin())
call self%compute_RGB(z, red, green, blue)
rgb_image(pixheight-j, 3*(i+1)-2) = red
rgb_image(pixheight-j, 3*(i+1)-1) = green
rgb_image(pixheight-j, 3*(i+1)) = blue
end do
end do
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',&
pixels = rgb_image)
call ppm%export_pnm(filename)
end subroutine write_ppm_colorbar