Load a .txt colormap with RGB integers separated by spaces on each line. Remark: if no path is indicated in filename, the .txt must be present at the root of the fpm project of the user.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(Colormap), | intent(inout) | :: | self | |||
character(len=*), | intent(in) | :: | filename | |||
real(kind=wp), | intent(in) | :: | zmin | |||
real(kind=wp), | intent(in) | :: | zmax | |||
logical, | intent(in), | optional | :: | reverse |
impure subroutine load(self, filename, zmin, zmax, reverse) class(Colormap), intent(inout) :: self character(*), intent(in) :: filename real(wp), intent(in) :: zmin, zmax logical, intent(in), optional :: reverse integer :: i, n integer :: red, green, blue logical :: file_found integer :: file_unit, ios inquire(file=filename, exist=file_found) if (file_found) then ! We first count the number of lines (RGB triplets): n = 0 open(newunit=file_unit, file=filename) do read(file_unit, '(3I3)', iostat=ios) red, green, blue if (ios /= 0) exit n = n + 1 end do close(file_unit) ! Is the colormap reseted? if (allocated(self%map)) then deallocate(self%map) end if allocate(self%map(0:n-1, 1:3)) ! Then we read them and put them in the map: open(newunit=file_unit, file=filename) do i = 0, n-1 read(file_unit, *, iostat=ios) red, green, blue self%map(i, 1:3) = [red, green, blue] ! Should not happen: if (ios /= 0) exit end do close(file_unit) self%name = trim(filename) self%zmin = zmin self%zmax = zmax self%levels = n call self%check(check_bounds=.true.) ! Reverse the colormap if requested if (present(reverse)) then if (reverse) call self%reverse() end if else stop "ERROR: COLORMAP FILE NOT FOUND!" end if end subroutine load