Extracts colors from the colormap based on specified number of levels (nl)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(Colormap), | intent(inout) | :: | self | |||
integer, | intent(in) | :: | extractedLevels | |||
character(len=*), | intent(in), | optional | :: | name | ||
real(kind=wp), | intent(in), | optional | :: | zmin | ||
real(kind=wp), | intent(in), | optional | :: | zmax | ||
logical, | intent(in), | optional | :: | reverse |
pure subroutine extract(self, extractedLevels, name, zmin, zmax, reverse) class(Colormap), intent(inout) :: self integer, intent(in) :: extractedLevels character(*), intent(in), optional :: name real(wp), intent(in), optional :: zmin, zmax logical, intent(in), optional :: reverse integer :: extracted_map(extractedLevels,3) integer :: ind(extractedLevels,3) real(wp) :: ind_rel(extractedLevels,3), array_rel(self%levels,3), step(3), current_element(3) integer :: i integer, dimension(self%levels,3) :: array character(3) :: extractedLevels_char ! Initialize array with indices do concurrent (i = 1: self%levels) array(i,:) = i-1 end do ! Normalize array elements to the range [0, 1] do concurrent (i = 1: 3) array_rel(:,i) = array(:,i)/ maxval(array(:,i)) end do ! Check if the number of extractedLevels is valid if (extractedLevels <= 1 .or. extractedLevels > self%levels) then error stop "Error: Invalid number of extractedLevels. Must be > 1 and <= levels" end if step(:) = array_rel(self%levels,:) / real(extractedLevels-1, kind=wp) current_element(:) = array_rel(1,:) do i = 1, extractedLevels ind_rel(i,:) = current_element current_element = current_element + step end do ! Scale interpolated indices to integers between 0 and self%levels - 1 do concurrent (i = 1:3) ind(:,i) = scale_real_int(ind_rel(:,i), 0, self%levels-1) end do ! Extract colors from the colormap based on interpolated indices do concurrent (i = 1: 3) extracted_map(:,i) = self%map(ind(:,i),i) end do ! Set colormap name if provided, otherwise use the number of levels as part of the name if (present(name)) then self%name = name else write(extractedLevels_char, '(I3)') extractedLevels self%name = self%name//trim(extractedLevels_char) end if ! Set zmin and zmax if provided if (present(zmin)) self%zmin = zmin if (present(zmax)) self%zmax = zmax ! Create the extracted colormap with the specified parameters call self%create(self%name, self%zmin, self%zmax, extracted_map) if (present(reverse)) then if (reverse) call self%reverse() end if end subroutine extract