;+
; NAME:
;       CTABLEPLOT
;
; PURPOSE:
;       Make a plot of a color table.
;
; CATEGORY:
;       Plotting tools.
;
; CALLING SEQUENCE:
;       ctableplot, num, /ps
;
; REQUIRED INPUTS:
;       None.
;
; OPTIONAL INPUTS:
;       num         number of the color table to be plotted
;
; KEYWORDS:
;       ps          make a postscript plot
;
; OUTPUTS:
;       EITHER a graphics window or a PS file containing the color table plot
;
; DESCRIPTION AND EXAMPLE:
;       This program opens a new graphics window or PS file and makes a plot
;       of all colors in the color table of the current or a specified color
;       table. The color table can be specified by NUM.
;
; CALLED BY:
;       none
;
; CALLING:
;       none
;
; MODIFICATION HISTORY:
;       2007-02-15 Written by Konrad R. Tristram
;       2009-05-04 Konrad R. Tristram: Renamed programme to "CTABLEPLOT".
;

PRO CTABLEPLOT, NUM, PS=PS

; LOAD COLOR TABLE IF SPECIFIED
; -----------------------------------------------------------------------------
if keyword_set(num) then begin
	loadct, num
	numstr = string(num, format='(I02)')
endif else numstr = ''

; MAKE PREPARATIONS FOR THE DIFFERENT PLOT TYPES
; -----------------------------------------------------------------------------
if keyword_set(ps) then begin
	!p.charsize=1.0
	set_plot, 'ps'
	device, file='colortable' + numstr + '.ps', $
                xsize=6.0, ysize=15.0, xoffset=7.5, yoffset=7.0, $
		/portrait, /color
endif else begin
	window, xsize=200, ysize=1000, /FREE
	!p.charsize=1.25
	device, decompose=0
endelse

; MAKE THE PLOT
; -----------------------------------------------------------------------------
plot, [0,1], [0,255], xs=5, ys=5, /nodata
for i=0,2550 do oplot, [0,1], [i/10.,i/10.], color=i/10
loadct, 0, /silent
plot, [0,1], [0,255], xs=1, ys=1, xticks=1, xtickname=[' ', ' '], yticklen=0.05, $
      ytitle='color index', xtitle='color table ' + numstr, $
      /nodata, /noerase

if keyword_set(ps) then begin
	device, /close
	set_plot, 'x'
endif else begin
	device, decompose=1
endelse

END

;+
; NAME:
;       CTABLEKRWT
;
; PURPOSE:
;       Redefine colour tables to my personal liking.
;
; CATEGORY:
;       General Tools.
;
; CALLING SEQUENCE:
;       ctablekrwt
;
; REQUIRED INPUTS:
;       None.
;
; OPTIONAL INPUTS:
;       None.
;
; KEYWORDS:
;       simple      also replace tables 01 and 08 by simpler ones
;
; OUTPUTS:
;       None.
;
; DESCRIPTION AND EXAMPLE:
;       This program modifies the colour tables available in IDL. The "Plasma" 
;       (32) colour table is replaced by a custom colour table, which is 
;       composed of several colour ranges. The "Rainbow + white" (39) colour 
;       table is replaced by a version where also darker red shades are 
;       included. Optionally, with the keyword SIMPLE set, the colour tables 
;       "BLUE/WHITE" (01) and "GREEN/WHITE LINEAR" (08) are replaced by simpler 
;       colour tables for the two respective colours.
;
; CALLED BY:
;       none
;
; CALLING:
;       none
;
; MODIFICATION HISTORY:
;       2007-02-15 Written by Konrad R. Tristram
;       2009-05-04 Konrad R. Tristram: Renamed programme to "CTABLEPLOT".
;

PRO CTABLEKRWT, SIMPLE=SIMPLE

; CREATE A CUSTOM COLOUR TABLE CONTAING ALL COLOURS AVER NEEDED
; ------------------------------------------------------------------------------
; CREATE A FEW REFERENCE ARRAYS
n=replicate(0,8)
f=findgen(8)
d=findgen(16)
; BLACK - GREY - WHITE
r=[16*findgen(16)]
g=[16*findgen(16)]
b=[16*findgen(16)]
; BLACK - RED - WHITE
r=[r, 32*f, 255+n]
g=[g, n, 32*f]
b=[b, n, 32*f]
; BLACK - GREEN - WHITE
r=[r, n, 32*f]
g=[g, 32*f, 255+n]
b=[b, n, 32*f]
; BLACK - BLUE - WHITE
r=[r, n, 32*f]
g=[g, n, 32*f]
b=[b, 32*f, 255+n]
; BLACK - YELLOW - WHITE
r=[r, 32*f, 255+n]
g=[g, 32*f, 255+n]
b=[b, n, 32*f]
; BLACK - CYAN - WHITE
r=[r, n, 32*f]
g=[g, 32*f, 255+n]
b=[b, 32*f, 255+n]
; BLACK - PINK - WHITE
r=[r, 32*f, 255+n]
g=[g, n, 32*f]
b=[b, 32*f, 255+n]
; BLACK - PINK - WHITE
r=[r, 255+n, 255-32*f, n, n, 32*f, 255+n]
g=[g, 32*f, 255+n, 255+n, 255-32*f, n, n]
b=[b, n, n, 32*f, 255+n, 255+n, 255-32*f]
; RAINBOW: BLACK - VIOLET - BLUE - CYAN - GREEN - YELLOW - RED - BLACK
r=[r, 96-1.5*(d-8)^2, n, n, n, n, 32*f, 255+n, 255+n, 255-16*d, 255+n]
g=[g, n, n, 32*f, 255-16*f, 128+n, 128+16*f, 255+n, 255-16*d, n, n, 255+n]
b=[b, 16*d, 255+n, 255-16*d, n, n, n, n, n, n, 255+n]
; LOAD AND MODIFY THE COLOUR TABLE ON DISK
tvlct, r,g,b
modifyct, 32, 'All my colours (KRWT)', r, g, b

; REPLACE THE DEFAULT "RAINBOW + WHITE" (39) COLOUR TABLE BY A NICER ONE
; ------------------------------------------------------------------------------
; BLACK - VIOLET - BLUE
r=[96-fix((indgen(48)-23.5)^2/552.25*96)]
g=[replicate(0,48)]
b=[indgen(48)*255/47]
; BLUE - CYAN
r=[r, replicate(  0,48)]
g=[g, indgen(48)*255/47]
b=[b, replicate(255,48)]
; CYAN - GREEN
r=[r, replicate(  0,32)]
g=[g, replicate(255,32)]
b=[b, 255-indgen(32)*255/31]
; GREEN - YELLOW
r=[r, indgen(32)*255/31]
g=[g, replicate(255,32)]
b=[b, replicate(  0,32)]
; YELLOW - ORANGE - RED
r=[r, replicate(255,48)]
g=[g, 255-indgen(48)*255/47]
b=[b, replicate(  0,48)]
; RED - BROWN - BLACK
r=[r, 255-indgen(48)*255/47]
g=[g, replicate(  0,48)]
b=[b, replicate(  0,48)]
; LAST COLOUR IS WHITE
r[255]=255
g[255]=255
b[255]=255
; LOAD AND MODIFY THE COLOUR TABLE ON DISK
tvlct, r,g,b
modifyct, 33, 'Rainbow + white (KRWT)', r, g, b

; REPLACE THE DEFAULT "BLUE/WHITE" (01) COLOUR TABLE BY A SIMPLER ONE
; ------------------------------------------------------------------------------
; BLACK - BLUE - WHITE
r=[replicate(0,128), indgen(128)*255/127]
g=[replicate(0,128), indgen(128)*255/127]
b=[indgen(128)*255/127, replicate(255,128)]
; LOAD AND MODIFY THE COLOUR TABLE ON DISK
tvlct, r,g,b
if keyword_set(simple) then modifyct, 01, 'SIMPLE BLUE/WHITE (KRWT)', r, g, b

; REPLACE THE DEFAULT "GREEN/WHITE LINEAR" (08) COLOUR TABLE BY A SIMPLER ONE
; ------------------------------------------------------------------------------
; BLACK - GREEN - WHITE
r=[replicate(0,128), indgen(128)*255/127]
g=[indgen(128)*255/127, replicate(255,128)]
b=[replicate(0,128), indgen(128)*255/127]
; LOAD AND MODIFY THE COLOUR TABLE ON DISK
tvlct, r,g,b
if keyword_set(simple) then modifyct, 08, 'SIMPLE GREEN/WHITE (KRWT)', r, g, b

END



