source: trunk/ToBeReviewed/COULEURS/colorbar.pro @ 19

Last change on this file since 19 was 19, checked in by pinsard, 18 years ago

upgrade of COULEURS according to cerbere.lodyc.jussieu.fr: /usr/home/smasson/SAXO_RD/ : files

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 12.4 KB
Line 
1;+
2; NAME:
3;   COLORBAR
4;
5; PURPOSE:
6;       The purpose of this routine is to add a color bar to the current
7;       graphics window.
8;
9; CATEGORY:
10;       Graphics, Widgets.
11;
12; CALLING SEQUENCE:
13;       COLORBAR
14;
15; INPUTS:
16;       None.
17;
18; KEYWORD PARAMETERS:
19;
20;       BOTTOM: The lowest color index of the colors to be loaded in
21;                 the bar.
22;
23;       CB_CHARSIZE: The character size of the color bar annotations. Default is 1.0.
24;
25;       CB_CHARTICK: The character thick of the color bar annotations. Default is 1.0.
26;
27;       CB_COLOR:    The color index of the bar outline and characters. Default
28;                 is ncolors - 1 + bottom.
29;
30;       CB_LOG: to get logarithmic scale for the colorbar
31;
32;       CB_TITLE:    This is title for the color bar. The default is to have
33;                 no title.
34;
35;       DISCRET:  Vecteur contenant les incices des couleurs a tracer en barre
36; de couleur. On obtient ainsi une barre de couleur discrete ne comportant que
37; les couleurs specifiees ds l'ordre ou elles apparaissent ds le vecteur.
38;
39;       DIVISIONS: The number of divisions to divide the bar into. There will
40;                 be (divisions + 1) annotations. The default is 2.
41;
42;       FORMAT:   The format of the bar annotations. Default is '(F6.2)'.
43;
44;       CB_LABEL:    C''est un vecteur qui specifie la valeur des sticks
45;       presents dans la barre de couleur. Il permet qd on utilise
46;       DISCRET d''avoir des couleurs qui ne s''incrementent pas de
47;       facon regulieres.
48;
49;       MAX:      The maximum data value for the bar annotation. Default is
50;                 NCOLORS-1.
51;
52;       MIN:      The minimum data value for the bar annotation. Default is 0.
53;
54;       NCOLORS:  This is the number of colors in the color bar.
55;
56;       NOTITLE:  oblige a ne pas mettre de titre meme si cb_title est declare
57;
58;       POSITION: A four-element array of normalized coordinates in the same
59;                 form as the POSITION keyword on a plot. Default is
60;                 [0.88, 0.15, 0.95, 0.95] for a vertical bar and
61;                 [0.15, 0.88, 0.95, 0.95] for a horizontal bar.
62;
63;       PSCOLOR:  This keyword is only applied if the output is being sent to
64;                 a PostScript file. It indicates that the PostScript device
65;                 is configured for color output. If this keyword is set, then
66;                 the annotation is drawn in the color specified by the COLOR
67;                 keyword. If the keyword is not set, the annotation is drawn
68;                 in the color specified by the !P.COLOR system variable
69;                 (usually this will be the color black). In general, this
70;                 gives better looking output on non-color or gray-scale
71;                 printers. If you are not specifically setting the annotation
72;                 color (with the COLOR keyword), it will probably
73;                 be better NOT to set this keyword either, even if you
74;                 are outputting to a color PostScript printer.
75;
76;       RIGHT:    This puts the labels on the right-hand side of a vertical
77;                 color bar. It applies only to vertical color bars.
78;
79;       TOP:      This puts the labels on top of the bar rather than under it.
80;                 The keyword only applies if a horizontal color bar is rendered.
81;
82;       VERTICAL: Setting this keyword give a vertical color bar. The default
83;                 is a horizontal color bar.
84;
85; COMMON BLOCKS:
86;       None.
87;
88; SIDE EFFECTS:
89;       Color bar is drawn in the current graphics window.
90;
91; RESTRICTIONS:
92;       The number of colors available on the display device (not the
93;       PostScript device) is used unless the NCOLORS keyword is used.
94;
95; EXAMPLE:
96;       To display a horizontal color bar above a contour plot, type:
97;
98;       LOADCT, 5, NCOLORS=100
99;       CONTOUR, DIST(31,41), POSITION=[0.15, 0.15, 0.95, 0.75], $
100;          C_COLORS=INDGEN(25)*4, NLEVELS=25
101;       COLORBAR, NCOLORS=100
102;
103; MODIFICATION HISTORY:
104;       Written by: David Fanning, 10 JUNE 96.
105;       10/27/96: Added the ability to send output to PostScript. DWF
106;       11/4/96: Substantially rewritten to go to screen or PostScript
107;           file without having to know much about the PostScript device
108;           or even what the current graphics device is. DWF
109;       1/27/97: Added the RIGHT and TOP keywords. Also modified the
110;            way the TITLE keyword works. DWF
111;       7/15/97: Fixed a problem some machines have with plots that have
112;            no valid data range in them. DWF
113;       3/3/98:  ajout du keyword discret par
114;                sebastien (smasson@lodyc.jussieu.fr)
115;-
116
117PRO COLORBAR, BOTTOM=bottom, CB_CHARSIZE=cb_charsize, CB_CHARTHICK=cb_charthick $
118              , CB_COLOR=cb_color, $
119              DIVISIONS=divisions, DISCRET=discret,CB_LABEL = cb_label, $
120              FORMAT=format, POSITION=position, MAX=max, MIN=min, NCOLORS=ncolors, $
121              PSCOLOR=pscolor, CB_TITLE=cb_title, VERTICAL=vertical, TOP=top, RIGHT=right, CB_LOG = CB_log, _extra = ex
122                                ; Is the PostScript device selected?
123
124   postScriptDevice = (!D.NAME EQ 'PS')
125
126                                ; Check and define keywords.
127
128   IF N_ELEMENTS(ncolors) EQ 0 THEN BEGIN
129
130                                ; Most display devices to not use the 256 colors available to
131                                ; the PostScript device. This presents a problem when writing
132                                ; general-purpose programs that can be output to the display or
133                                ; to the PostScript device. This problem is especially bothersome
134                                ; if you don't specify the number of colors you are using in the
135                                ; program. One way to work around this problem is to make the
136                                ; default number of colors the same for the display device and for
137                                ; the PostScript device. Then, the colors you see in PostScript are
138                                ; identical to the colors you see on your display. Here is one way to
139                                ; do it.
140
141      IF postScriptDevice THEN BEGIN
142         oldDevice = !D.NAME
143
144                                ; What kind of computer are we using? SET_PLOT to appropriate
145                                ; display device.
146
147         thisOS = !VERSION.OS_FAMILY
148         thisOS = STRMID(thisOS, 0, 3)
149         thisOS = STRUPCASE(thisOS)
150         CASE thisOS of
151            'MAC': SET_PLOT, thisOS
152            'WIN': SET_PLOT, thisOS
153            ELSE: SET_PLOT, 'X'
154         ENDCASE
155         !p.BACKGROUND=(!d.n_colors-1) < 255
156         !p.color=0
157         if !d.n_colors gt 256 then !p.background='ffffff'x
158
159                                ; Open a window (to make sure !D.N_COLORS is accurate).
160
161         WINDOW, /FREE, /PIXMAP, XSIZE=10, YSIZE=10
162         WDELETE, !D.WINDOW
163
164                                ; Here is how many colors we should use.
165
166         ncolors = !D.N_COLORS
167         SET_PLOT, oldDevice
168         IF oldDevice EQ 'X' OR oldDevice EQ 'MAC' OR oldDevice EQ 'WIN' then BEGIN
169            !p.BACKGROUND=(!d.n_colors-1) < 255
170            !p.color=0
171            if !d.n_colors gt 256 then !p.background='ffffff'x
172         ENDIF
173      ENDIF ELSE ncolors = !D.N_COLORS
174   ENDIF
175   IF N_ELEMENTS(bottom) EQ 0 THEN bottom = 0B
176   IF N_ELEMENTS(cb_charsize) EQ 0 THEN cb_charsize = 1.0
177   IF N_ELEMENTS(cb_charthick) EQ 0 THEN cb_charthick = 1.0
178   IF N_ELEMENTS(format) EQ 0 THEN format = '(F6.2)'
179   IF N_ELEMENTS(cb_color) EQ 0 THEN cb_color = ncolors - 1 + bottom
180   IF N_ELEMENTS(min) EQ 0 THEN min = 0.0
181   IF N_ELEMENTS(max) EQ 0 THEN max = FLOAT(ncolors) - 1
182   IF N_ELEMENTS(divisions) EQ 0 THEN divisions = 2
183   IF N_ELEMENTS(cb_title) EQ 0 THEN cb_title = ''
184   IF N_ELEMENTS(notitle) EQ 1 THEN cb_title = ''
185   pscolor = KEYWORD_SET(pscolor)
186
187   IF KEYWORD_SET(vertical) THEN BEGIN
188      IF KEYWORD_SET(discret) THEN begin
189         facteur=256/n_elements(discret)
190         discret=reform(replicate(1,facteur) # discret,facteur*n_elements(discret), /overwrite)
191         bar = REPLICATE(1B,10) # discret
192      endif else  bar = REPLICATE(1B,10) # BINDGEN(256)
193      IF N_ELEMENTS(position) EQ 0 THEN position = [0.88, 0.15, 0.95, 0.95]
194   ENDIF ELSE BEGIN
195      IF KEYWORD_SET(discret) THEN begin
196         facteur=256/n_elements(discret)
197         discret=reform(replicate(1,facteur) # discret,facteur*n_elements(discret), /overwrite)
198         bar =  discret # REPLICATE(1B,10)
199      endif else bar = BINDGEN(256) # REPLICATE(1B, 10)
200      IF N_ELEMENTS(position) EQ 0 THEN position = [0.15, 0.88, 0.95, 0.95]
201   ENDELSE
202
203                                ; Scale the color bar.
204   IF NOT KEYWORD_SET(discret) THEN $
205    bar = BYTSCL(bar, TOP=ncolors-1) + bottom
206
207                                ; Get starting locations in DEVICE coordinates.
208
209   xstart = position(0) * !D.X_VSIZE
210   ystart = position(1) * !D.Y_VSIZE
211
212                                ; Get the size of the bar in DEVICE coordinates.
213
214   xsize = (position(2) - position(0)) * !D.X_VSIZE
215   ysize = (position(3) - position(1)) * !D.Y_VSIZE
216
217                                ; For PostScript output only, draw the annotation in !P.COLOR
218                                ; unless "pscolor" is set. This makes better output on grayscale
219                                ; printers.
220
221   IF postScriptDevice AND (pscolor NE 1) THEN BEGIN
222      oldcolor = cb_color
223      cb_color = !P.COLOR
224   ENDIF
225
226                                ; Display the color bar in the window. Sizing is
227                                ; different for PostScript and regular display.
228
229   IF postScriptDevice THEN BEGIN
230
231      TV, bar, xstart, ystart, XSIZE=xsize, YSIZE=ysize
232
233   ENDIF ELSE BEGIN
234
235      bar = CONGRID(bar, CEIL(xsize), CEIL(ysize), /INTERP)
236      TV, bar, xstart, ystart
237
238   ENDELSE
239
240                                ; Annotate the color bar.
241
242   if keyword_set(cb_label) then begin
243      divisions = n_elements(cb_label)-1
244      for i = 0,divisions DO cb_label = string(cb_label, FORMAT = format)
245      format = ''
246   ENDIF ELSE cb_label = ''
247
248
249   IF KEYWORD_SET(vertical) THEN BEGIN
250
251      IF KEYWORD_SET(right) THEN BEGIN
252
253         PLOT, [min,max], [min,max], /NODATA, XTICKS=1, $
254          YTICKS=divisions, XSTYLE=1, YSTYLE=9, $
255          POSITION=position, COLOR=cb_color, CHARSIZE=cb_charsize, CHARTHICK=cb_charthick $
256          , /NOERASE, $
257          YTICKFORMAT='(A1)', XTICKFORMAT='(A1)', YTICKLEN=0.1 , $
258          YRANGE=[min, max], YTITLE=cb_title
259
260         AXIS, YAXIS=1, YRANGE=[min, max], YTICKFORMAT=format, YTICKS=divisions, $
261          YTICKLEN=0.1, YSTYLE=1, COLOR=cb_color, CHARTHICK=cb_charthick $
262          , CHARSIZE=cb_charsize, xtickname = cb_label, ylog = cb_log
263
264      ENDIF ELSE BEGIN
265
266         PLOT, [min,max], [min,max], /NODATA, XTICKS=1, $
267          YTICKS=divisions, XSTYLE=1, YSTYLE=9, $
268          POSITION=position, COLOR=cb_color, CHARSIZE=cb_charsize $
269          , CHARTHICK=cb_charthick, /NOERASE, $
270          YTICKFORMAT=format, XTICKFORMAT='(A1)', YTICKLEN=0.1 , $
271          YRANGE=[min, max], xtickname = cb_label
272
273         AXIS, YAXIS=1, YRANGE=[min, max], YTICKFORMAT='(A1)', YTICKS=divisions, $
274          YTICKLEN=0.1, YTITLE=cb_title, YSTYLE=1, COLOR=cb_color $
275          , CHARSIZE=cb_charsize, CHARTHICK=cb_charthick, ylog = cb_log
276
277      ENDELSE
278
279   ENDIF ELSE BEGIN
280
281      IF KEYWORD_SET(top) THEN BEGIN
282
283         PLOT, [min,max], [min,max], /NODATA, XTICKS=divisions, $
284          YTICKS=1, XSTYLE=9, YSTYLE=1, $
285          POSITION=position, COLOR=cb_color, CHARSIZE=cb_charsize $
286          , CHARTHICK=cb_charthick, /NOERASE, $
287          YTICKFORMAT='(A1)', XTICKFORMAT='(A1)', XTICKLEN=0.1, $
288          XRANGE=[min, max], XTITLE=cb_title
289
290         AXIS, XTICKS=divisions, XSTYLE=1, COLOR=cb_color $
291          , CHARSIZE=cb_charsize, CHARTHICK=cb_charthick, $
292          XTICKFORMAT=format, XTICKLEN=0.1, XRANGE=[min, max], XAXIS=1, xtickname = cb_label, xlog = cb_log
293
294      ENDIF ELSE BEGIN
295
296         PLOT, [min,max], [min,max], /NODATA, XTICKS=divisions, $
297          YTICKS=1, XSTYLE=1, YSTYLE=1, $
298          POSITION=position, COLOR=cb_color, CHARSIZE=cb_charsize $
299          , CHARTHICK=cb_charthick, /NOERASE, $
300          YTICKFORMAT='(A1)', XTICKFORMAT=format, XTICKLEN=0.1, $
301          XRANGE=[min, max], TITLE=cb_title, xtickname = cb_label, xlog = cb_log
302
303      ENDELSE
304
305   ENDELSE
306                                ; Restore color variable if changed for PostScript.
307
308   IF postScriptDevice AND (pscolor NE 1) THEN cb_color = oldcolor
309
310   return
311END
Note: See TracBrowser for help on using the repository browser.