New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
colorbar_idl.pro in branches/UKMO/r6232_tracer_advection/NEMOGCM/TOOLS/OBSTOOLS/dataplot – NEMO

source: branches/UKMO/r6232_tracer_advection/NEMOGCM/TOOLS/OBSTOOLS/dataplot/colorbar_idl.pro @ 9295

Last change on this file since 9295 was 3002, checked in by djlea, 13 years ago

Update documentation for obstools and dataplot. Removal of dataplot code not needed. Addition of headers to some dataplot code. Addition of .exe to command example in obstools.

File size: 6.6 KB
Line 
1;+
2PRO colorbar_idl, datain, colors, lablevels, datalevels, data=data, $
3   textcolor=textcolor, mincolor=mincolor, position=position
4;--------------------------------------------------------------------
5; datain - gives the range of values which are represented by colors
6; colors - color values
7; lablevels - label levels
8;
9; Author:  D. J. Lea    Nov 2008
10;--------------------------------------------------------------------
11
12; keep current graphics keywords
13
14psave=!p
15xsave=!x
16ysize=!y
17
18   if (n_elements(mincolor) eq 3) then $
19         TVLCT,mincolor(0),mincolor(1),mincolor(2),0
20
21    mx=max(datain,min=mn)
22
23   normal=1
24   if (keyword_set(data)) then normal=0
25
26   
27    if (keyword_set(data)) then begin           ; data coords
28    y1 = !y.crange(0)-0.1*(!y.crange(1)-!y.crange(0))     
29    y2 = !y.crange(0)-0.05*(!y.crange(1)-!y.crange(0))
30    x1 = !x.crange(0)+0.1*(!x.crange(1)-!x.crange(0))
31    x2 = !x.crange(0)+0.9*(!x.crange(1)-!x.crange(0))
32    endif else begin                ; normal coords
33    y1 = !y.window(0)-0.11*(!y.window(1)-!y.window(0))     
34    y2 = !y.window(0)-0.05*(!y.window(1)-!y.window(0))
35;;    y1 = !y.window(0)+0.05*(!y.window(1)-!y.window(0))     
36;;    y2 = !y.window(0)+0.1*(!y.window(1)-!y.window(0))
37    x1 = !x.window(0)+0.076*(!x.window(1)-!x.window(0))
38    x2 = !x.window(0)+0.924*(!x.window(1)-!x.window(0))
39    endelse
40
41    if (n_elements(position) eq 4) then begin
42      coords=position
43    endif else begin
44   coords=[x1,y1,x2,y2]
45    endelse
46
47    print,'coords: ',coords
48   print, 'normal: ',normal, ' data: ',keyword_set(data)
49
50;    nb = N_ELEMENTS(colors)               
51;    x=coords(0)+(coords(2)-coords(0))*findgen(nb+1)/nb
52;   
53;    FOR i=0,nb-1 DO BEGIN
54;;    print,colors(i)
55;    polyfill, transpose([[x(i),x(i+1),x(i+1),x(i),x(i)],$
56;      [coords(1),coords(1),coords(3),coords(3),coords(1)]]),$
57;      color=colors(i), data=data, normal=normal
58;    ENDFOR
59
60;Position is always in normal units will need to do a conversion if
61; data units required...
62
63    fill=0
64    cell_fill=1
65
66    maxdat=mx
67    mindat=mn
68    if (n_elements(datalevels) gt 0) then begin
69       maxdat=max(datalevels,min=mindat)
70;            mindat=mindat+(1./!d.table_size)*(maxdat-mindat)
71;            print,'datalevels ',datalevels
72    endif
73
74; fix to prevent zero contour range
75    if (maxdat eq mindat) then begin
76        if (maxdat eq 0) then begin
77      maxdat = maxdat + 1e-20
78        mindat = mindat - 1e-20
79        endif else begin
80        maxdat = maxdat * 1.01
81        mindat = mindat * 0.99
82        if (maxdat lt mindat) then begin
83         tmp = mindat
84                mindat = maxdat
85                maxdat = tmp
86        endif
87        endelse
88    endif
89   
90    array1d=(findgen(!d.table_size+1))/!d.table_size*(maxdat-mindat)+mindat
91;    array1d=(findgen(!d.table_size+10)-10)/!d.table_size*(maxdat-mindat)+mindat
92
93   print,'!d.table_size ',!d.table_size
94
95;  print,'array1d ',array1d
96        print,'min array1d ',min(array1d), max(array1d)
97        print,'datain ',datain
98        print,'mx ',mx,' mn ',mn
99
100    if (n_elements(datalevels) gt 0) then print, 'datalevels ', datalevels
101       
102    array2d=array1d#replicate(1,2)
103    if (n_elements(datalevels) lt 2) then datalevels=array1d
104   
105;    print, 'datalevels ', datalevels
106;  print,'cell_fill ',cell_fill
107
108    TVLCT, R, G, B, /get
109    TVLCT,R(1),G(1),B(1),0        ; bodge fix for wrong black contour   
110
111   if (n_elements(data) gt 0) then print,'data = ',data
112        if (n_elements(normal) gt 0) then print,'normal = ',normal
113        print,coords
114
115; draw a few times to remove gaps
116    nel=n_elements(datalevels)
117    print, 'datalevels ',datalevels(0), datalevels(nel-1), nel
118    print, 'array2d ',min(array2d), max(array2d)
119    if (datalevels(0) lt datalevels(nel-1)) then begin
120    for i=0,2 do begin   
121    contour, array2d, levels=datalevels, fill=fill, cell_fill=cell_fill, $
122    POSITION=coords, /noerase, xstyle=5, ystyle=5, data=data, normal=normal
123    endfor
124    endif
125
126    TVLCT,R(0),G(0),B(0),0
127
128    numlablevels=n_elements(lablevels)
129    sigfig=1
130   strlabs=strarr(numlablevels)
131
132   repeat begin
133        widstr=strtrim(string(sigfig+8),2)
134; output 2 significant figures except if 0.
135
136        for i = 0, numlablevels-1 do begin
137        format='(g'+widstr+'.'+strtrim(string(sigfig),2)+')'
138   strlabs(i)=strcompress(string(lablevels(i),format=format),/remove_all)
139
140;  print,i,'.',strlabs(i),'.',format
141
142        if (strmid(strlabs(i),0,1) eq '0' or strmid(strlabs(i),0,2) eq '-0') then begin
143         format='(g'+widstr+'.'+strtrim(string(sigfig-1),2)+')'
144           strlabs(i)=strcompress(string(lablevels(i),format=format),/remove_all)
145;                print,i,'.',strlabs(i),'.',format               
146        endif
147
148;  print,i,'.',strlabs(i),'.',format
149
150; trim out spaces
151   strlabs(i)=strtrim(strlabs(i),2)
152       
153        strtemp=strlabs(i)
154; strip off last two characters if there is 0 after the decimal place
155; with a number thereafter
156        ptpos=strpos(strtemp,'.0')
157        len=strlen(strtemp)
158;        if ptpos gt 0 then print,ptpos,len
159        if ptpos gt 0 and len-2 ge ptpos then begin
160      strlabs(i)=strmid(strtemp,0,len-1)             
161        endif
162
163;if the remaining last character is a point (.) then get rid of it
164   ptpos=strpos(strlabs(i),'.')
165        len=strlen(strlabs(i))
166;  print,ptpos, len
167   if ptpos gt 0 and ptpos eq len-1 then begin
168         strlabs(i)=strmid(strlabs(i),0,len-1)
169        endif
170       
171        endfor
172;        print,strlabs
173;        print,strlen(strlabs)
174        sigfig=sigfig+1
175        whe=where(strpos(strlabs,'e') gt 0, numexps)
176;        print,'whe ',whe, numexps
177; all labels should be unique
178; should be all exps or none
179; give up if sigfigs 255       
180   endrep until (n_elements(unique(strlabs)) eq numlablevels $
181         and (numexps eq 0 or numexps eq numlablevels) $
182         or sigfig gt 255)
183
184    pcharsize=!p.charsize
185    if (pcharsize lt 1) then pcharsize=1
186;    tolx=0.01*pcharsize*(!x.crange(1)-!x.crange(0))
187    tolx=0.01*(x2-x1)
188   
189    ypos = y1-0.02*pcharsize*(!y.crange(1)-!y.crange(0))
190    for i = 0, numlablevels-1 do begin
191;      xpos = x1 + float(i)/float(n_elements(lablevels)-1)*(x2-x1)
192   xpos = x1 + (lablevels(i)-mn)/(mx-mn)*(x2-x1)      ; position labels correctly relative
193
194   if (xpos ge x1-tolx and xpos le x2+tolx) then begin   ; don't print any labels off the edge
195
196;      xyouts, xpos, ypos, strcompress(string(lablevels(i),format='(f7.2)'),/remove_all), $
197;              color=!d.table_size-1, data=data, normal=normal, align=0.5
198
199   if (n_elements(textcolor) eq 3) then $
200         TVLCT,textcolor(0),textcolor(1),textcolor(2),0
201;  print,'xyouts ',xpos, ypos, ' ',strlabs(i)
202        xyouts, xpos, ypos, strlabs(i), data=data, normal=normal, align=0.5
203   endif
204
205    endfor
206
207; restore graphics keywords
208!p=psave
209!x=xsave
210!y=ysize
211                   
212END
Note: See TracBrowser for help on using the repository browser.