
FUNCTION eis_mapper_aia_rgb, wavelnth

;+
; NAME:
;     EIS_MAPPER_AIA_RGB
;
; PURPOSE:
;     Loads an IDL RGB table for the specified AIA wavelength.
;
; CATEGORY:
;     EIS Mapper; AIA; color table.
;
; CALLING SEQUENCE:
;     Result = EIS_MAPPER_AIA_RGB( Wavelnth )
;
; INPUTS:
;     Wavelnth: An AIA wavelength in angstroms.
;
; OUTPUTS:
;     Returns a 2D array of size [256,3] containing the RGB table for
;     the specified AIA wavelength. If a problem is found then a value
;     of -1 is returned.
;
; EXAMPLE:
;     IDL> rgb_table=eis_mapper_aia_rgb(193)
;
; MODIFICATION HISTORY:
;     Ver.1, 31-Mar-2020, Peter Young
;       Uses the code from aia_lct.pro. I created this because aia_lct
;       requires the DISPLAY environment variable to be set, which is
;       no good when running the routine on a remote server.
;     Ver.2, 19-Jan-2021, Peter Young
;       Fixed error message warning, no change to code.
;-


loadct,3,rgb_table=rgb_table
r0=rgb_table[*,0]
g0=rgb_table[*,1]
b0=rgb_table[*,2]

;loadct,3,/silent
;tvlct,r0,g0,b0,/get
c0=byte(findgen(256))
c1=byte(sqrt(findgen(256))*sqrt(255.))
c2=byte(findgen(256)^2/255.)
c3=byte((c1+c2/2.)*255./(max(c1)+max(c2)/2.))

; allowed values of wavelnth:
wave=[1600,1700,4500,94,131,171,193,211,304,335,6173,1]
select=where(nint(wavelnth) eq wave)
if select(0) eq -1 then begin
  print,'% EIS_MAPPER_AIA_RGB: selected invalid wavelength/channel'
  return,-1
endif 

case select of
0: begin  ; 1600
   r=c3
   g=c3
   b=c2
   end
1: begin  ; 1700
   r=c1
   g=c0
   b=c0
   end
2: begin  ; 4500
   r=c0
   g=c0
   b=byte(b0/2)
   end
3: begin  ; 94
   r=c2
   g=c3
   b=c0
   end
4: begin  ; 131
   r=g0
   g=r0
   b=r0
   end
5: begin  ; 171
   r=r0
   g=c0
   b=b0
   end
6: begin  ; 193
   r=c1
   g=c0
   b=c2
   end
7: begin  ; 211
   r=c1
   g=c0
   b=c3
   end
8: begin  ; 304
   r=r0
   g=g0
   b=b0 ; changed from c2 on 2010/06/01, now to show standard IDL color table 3
   end
9: begin  ; 355
   r=c2
   g=c0
   b=c1
   end
10: begin  ; 6173 (HMI continuum)
   r=c0
   g=c0
   b=byte(b0/2)
   end
11: begin  ; 1 (HMI B_LOS)
   r=c0
   g=c0
   b=c0
   end
endcase

rgb_table=[[r],[g],[b]]

return,rgb_table

END
