
;
; Copyright (c) 1998, Forschungszentrum Juelich GmbH ICG-1
; All rights reserved.
; Unauthorized reproduction prohibited.
; This software may be used, copied, or redistributed as long as it is not
; sold and this copyright notice is reproduced on each copy made.  This
; routine is provided as is without any express or implied warranties
; whatsoever.
;
;+
; NAME:
;  def_colorsystem
;
; PURPOSE:
;  This procedure defines the colors for the colorsystem
;
; CATEGORY:
;   PLOT/PLOT2D
;
; CALLING SEQUENCE:
;   def_colorsystem,[colors=colors],[start_color=start_color],[max_colors=max_colors]
;
; KEYWORD PARAMETERS:
;   colors=colors:           the RGB color code which describe the colors
;                            default comes from ct_fr2
;   start_color=start_color: the beginning index of the colorsystem
;                            default is 20
;   max_colors=max_colors:   the number of indices belonging to the colorsystem
;                            default is def_n_colors()-1
;
; EXAMPLE:
;   def_colorsystem,start=100,max_colors=50
;   erase
;   cbar
;
; MODIFICATION HISTORY:
; 	Written by:	R.Bauer (ICG-1), 1998-Jul-09
;-
PRO def_colorsystem,colors=colors,start_color=start_color,max_colors=max_colors


   TVLCT,red,green,blue ,/get


   IF N_ELEMENTS(colors) EQ 0 THEN a=EXECUTE('ct_yellow_red_blue_green_black,colors=colors')
   IF N_ELEMENTS(max_colors) EQ 0 THEN  BEGIN
      IF !d.n_colors GT 256 THEN max_colors=256-1 ELSE max_colors=!d.n_colors-1
   ENDIF
   IF N_ELEMENTS(start_color) EQ 0 THEN start_color=20

   IF !d.n_colors GT 256 THEN av_colors=256-1 ELSE av_colors=!d.n_colors-1


   IF av_colors EQ max_colors-1 OR av_colors EQ max_colors OR start_color+max_colors EQ 256 THEN BEGIN

      stat=(max_colors-start_color)/FLOAT((N_ELEMENTS(colors[*,0])-1.))


      x=ROUND((FINDGEN(N_ELEMENTS(colors[*,0]))*stat)+start_color) ; auf diese indizes bezieht sich colors von

      x2=FINDGEN(max_colors-start_color)+start_color

      red[start_color:max_colors-1]=INTERPOL(colors[*,0],x,x2)
      green[start_color:max_colors-1]=INTERPOL(colors[*,1],x,x2)
      blue[start_color:max_colors-1]=INTERPOL(colors[*,2],x,x2)

      ENDIF ELSE BEGIN
      stat=(max_colors)/FLOAT((N_ELEMENTS(colors[*,0])-1))

      x=ROUND((FINDGEN(N_ELEMENTS(colors[*,0]))*stat))+start_color ; auf diese indizes bezieht sich colors
      x2=FINDGEN(max_colors)+start_color

      red[start_color:max_colors+start_color-1]=INTERPOL(colors[*,0],x,x2)
      green[start_color:max_colors+start_color-1]=INTERPOL(colors[*,1],x,x2)
      blue[start_color:max_colors+start_color-1]=INTERPOL(colors[*,2],x,x2)
   ENDELSE


; All indices to 255 s
   IF N_ELEMENTS(red) LT 255 THEN BEGIN
      rest=255-N_ELEMENTS(red)
      red=[red,REPLICATE(255,rest)]
      green=[green,REPLICATE(255,rest)]
      blue=[blue,REPLICATE(255,rest)]
      ENDIF ELSE BEGIN
      red[255]=255
      green[255]=255
      blue[255]=255

   ENDELSE


   TVLCT,red,green,blue




END










