write_ppm_colorbar Subroutine

private impure subroutine write_ppm_colorbar(self, filename, width, height, encoding)

Uses

    • forimage
  • proc~~write_ppm_colorbar~~UsesGraph proc~write_ppm_colorbar Colormap%write_ppm_colorbar forimage forimage proc~write_ppm_colorbar->forimage

Type Bound

Colormap

Arguments

Type IntentOptional Attributes Name
class(Colormap), intent(inout) :: self
character(len=*), intent(in) :: filename
integer, intent(in), optional :: width
integer, intent(in), optional :: height
character(len=*), intent(in), optional :: encoding

Calls

proc~~write_ppm_colorbar~~CallsGraph proc~write_ppm_colorbar Colormap%write_ppm_colorbar export_pnm export_pnm proc~write_ppm_colorbar->export_pnm get_format get_format proc~write_ppm_colorbar->get_format proc~compute_rgb Colormap%compute_RGB proc~write_ppm_colorbar->proc~compute_rgb proc~get_zmax Colormap%get_zmax proc~write_ppm_colorbar->proc~get_zmax proc~get_zmin Colormap%get_zmin proc~write_ppm_colorbar->proc~get_zmin set_format set_format proc~write_ppm_colorbar->set_format set_pnm set_pnm proc~write_ppm_colorbar->set_pnm proc~get_rgb Colormap%get_RGB proc~compute_rgb->proc~get_rgb

Called by

proc~~write_ppm_colorbar~~CalledByGraph proc~write_ppm_colorbar Colormap%write_ppm_colorbar program~create create program~create->proc~write_ppm_colorbar program~demo demo program~demo->proc~write_ppm_colorbar program~demo_reverse demo_reverse program~demo_reverse->proc~write_ppm_colorbar program~example1 example1 program~example1->proc~write_ppm_colorbar program~extract extract program~extract->proc~write_ppm_colorbar program~modify modify program~modify->proc~write_ppm_colorbar

Source Code

    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